Patiencer / thtmlviewer

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

text-decoration not handled correctly with multiple properties #409

Closed GoogleCodeExporter closed 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

GoogleCodeExporter commented 9 years ago
I have observed same issue - but without using of CSS. Simple html-code like 
this will only display the text underlined:
...
<p><strike><u>STRIKE + UNDERLINE</u></strike></p>
...
But the text is not strikethroughed.

If I change the direction of the properties from "<strike><u>...</u></strike>" 
to "<u><strike>...</strike></u>" you will only see the text strikethrough - but 
not underlined.

I think there is something wrong while collection the properties for the same 
section. I look likes the 'last' property wins always for the same section and 
they are not merged as expected. Can you confirm my obervation?

Original comment by hugomaye...@googlemail.com on 26 May 2015 at 1:59

GoogleCodeExporter commented 9 years ago
Thanks for spotting this issue

Original comment by OrphanCat on 27 Jul 2015 at 7:31

GoogleCodeExporter commented 9 years ago
Thanks for investigating this issue.

Original comment by OrphanCat on 27 Jul 2015 at 7:37

GoogleCodeExporter commented 9 years ago
https://github.com/BerndGabriel/HtmlViewer/commit/c3230eea5e5e5f464224a3e2b5a6ef
7662604d89 fixes this issue

Original comment by OrphanCat on 27 Jul 2015 at 7:42

GoogleCodeExporter commented 9 years ago
Thanks a lot for the fix... I have merged your change-set into our locale 
sources and it seems to work for our interests.

Original comment by hugomaye...@googlemail.com on 28 Jul 2015 at 1:56

GoogleCodeExporter commented 9 years ago
Looks good, however POS() is CaseSensitive. So if i write "UnderLine" it will 
not match. AFAIK CSS is case insensitive. ContainsText might be a better option 
here.

Original comment by Sebal...@googlemail.com on 28 Jul 2015 at 4:58

GoogleCodeExporter commented 9 years ago
@sebal007

"Underline" works as well as style values are converted to lowercase before 
processing. Pos is much cheaper than ContainsText.

Original comment by OrphanCat on 28 Jul 2015 at 7:11

GoogleCodeExporter commented 9 years ago
didn't know they are made lowercase. in this case, Pos is much better, of 
course.

Original comment by Sebal...@googlemail.com on 30 Jul 2015 at 7:13