kooloveme / thtmlviewer

Automatically exported from code.google.com/p/thtmlviewer
Other
0 stars 0 forks source link

text-decoration not handled correctly with multiple properties #409

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
the Inline-CSS property Text-decoration allows multiple values(underline, line 
through)

However, the source can not deal with it, when both are set, as it always 
compares to

value = 'underline'
or
value = 'line-through'

which fails when it is noted as
text-decoration: underline line-through

in this case value is 'underline line-through' an nothing happens as this value 
is not expected. I fixed this for TProperties.GetSingleFontInfo(however, might 
still occur in TProperties.combine)

diff --git a/StyleUn.pas
index 7c7c662..037ec64 100644
--- a/StyleUn.pas
+++ b/StyleUn.pas
@@ -223,6 +223,7 @@ type
     procedure AssignCodePage(const CP: Integer);
     procedure CalcLinkFontInfo(Styles: TStyleList; I: Integer);
     procedure GetSingleFontInfo(var Font: ThtFontInfo);
+    function GetTextDecoration(): TFontStyles;
   public
     PropSym: TElemSymb;
     PropTag, PropClass, PropID, PropPseudo, PropTitle: ThtString;
@@ -482,6 +483,8 @@ procedure ApplyBoxSettings(var AMarg : TMarginArray; const 
AUseQuirksMode : Bool

 implementation
 uses
+  Types,
+  StrUtils,
 {$ifdef Compiler24_Plus}
   System.UITypes,
 {$endif}
@@ -1581,6 +1584,25 @@ begin
     Result := -1;
 end;

+function TProperties.GetTextDecoration: TFontStyles;
+var
+  LProperties: TStringDynArray;
+  LProperty: string;
+begin
+  Result := [];
+  LProperties := SplitString(Props[TextDecoration], ' ');
+  for LProperty in LProperties do
+  begin
+    if SameText(LProperty, 'underline') then
+    begin
+      Result := Result + [fsUnderline];
+    end else if SameText(LProperty, 'line-through') then
+    begin
+      Result := Result + [fsStrikeOut];
+    end;
+  end;
+end;
+
 function TProperties.GetTextIndent(out PC: Boolean): Integer;
 var
   I: Integer;
@@ -2915,10 +2937,8 @@ begin {call only if all things valid}
   end;
   if (Props[FontStyle] = 'italic') or (Props[FontStyle] = 'oblique') then
     Include(Style, fsItalic);
-  if Props[TextDecoration] = 'underline' then
-    Include(Style, fsUnderline)
-  else if Props[TextDecoration] = 'line-through' then
-    Include(Style, fsStrikeOut);
+
+  Style := Style + GetTextDecoration();
   Font.iStyle := Style;
   Font.iSize := Props[FontSize];
   Font.iCharset := CharSet;

Original issue reported on code.google.com by Sebal...@googlemail.com on 18 Mar 2015 at 3:39