Format AsWebpage problems + sollution

  • WpTools 6.13.1

    In our application we have started using the (relatively new) AsWebPage property. This could finally enable us to use wptools as a html viewer for email. Prior to this we could only use wptools for composing an email, but when we our application for example received a newsletter we relied on different components to view them.

    So, a big thank you for this.

    So this week i have started implementing and testing the feature and found a few problems with it.

    Problem 1:
    Painting before line text seems to occur after the line text is drawn. For us this only seems to go wrong with certain tables. (If needed i can provide a demo)
    I do not yet understand why wpFormatAsWebpage influences the behavior, but i did find the following in the code that seems wrong.

    Code
    if assigned( _OnInternPaintPar ) then      begin         _OnInternPaintPar(_EditBox, wpBeforeLineText, Self, LineData, rtfpage, LineData.Par,            LineData.LineNr, DestCanvas, ParColorOverride, TextColorOverride, AnyObject, StandardIgnore);      end;.....if assigned( _OnInternPaintPar ) then      begin         _OnInternPaintPar(_EditBox, wpAfterLineText, Self, LineData, rtfpage, LineData.Par,            LineData.LineNr, DestCanvas, ParColorOverride, TextColorOverride, AnyObject, StandardIgnore);      end;      {$ENDIF}.....            {$IFDEF WP6}      ParColorOverride := clNone;      TextColorOverride:= clNone;      AnyObject := nil;      StandardIgnore := false;      if assigned( _OnInternPaintPar ) then      begin         _OnInternPaintPar(_EditBox, wpBeforeLineText, Self, LineData, rtfpage, LineData.Par,            LineData.LineNr, DestCanvas, ParColorOverride, TextColorOverride, AnyObject, StandardIgnore);      end;      {$ENDIF}if ...elsebegin  ....  if ...  begin  end  else  try     ...    PaintLine    if assigned( _OnInternPaintPar ) then      begin         _OnInternPaintPar(_EditBox, wpAfterLineText, Self, LineData, rtfpage, LineData.Par,            LineData.LineNr, DestCanvas, ParColorOverride, TextColorOverride, AnyObject, StandardIgnore);      end;  except  end;

    It seems the second call to _OnInternPaintPar with parameter wpBeforeLineText should be within the same compound statement as the call with PaintLine and the last _OnInternPaintPar. Now it is possible "wpBeforeLineText" is executed without a following call to "LineText" and "wpAfterLineText"

    Problem 2:
    Hiding paragraphs with paragraph property paprHidden doesn't work anymore.
    Tracing this in the code was difficult, but it seems wpFormatAsWebPage calls a different format routine for the paragraph, which means that it differs on several thousands lines of code. This does make me wonder how much more paragraph functionality is now lost, but maybe i'm looking at it the wrong way.

    I did find a way to "solve" this in the code. See below. Change has been marked with {$IFDEF OBEC}

    It is difficult to see if there is a downside to this fix. And i'm not sure it will prove strong enough.

  • I can't demonstrate problem 1 with just a html file, because the problem occurs when the _OnInternPaintPar event is used for drawing. I would need to construct a demo application to demonstrate this. Right now i don't have the time to produce one, but i feel the code itself should be obvious.

    simple application to demonstrate problem 2:

    You'll notice the first paragraph is no longer hidden when wpFormatAsWebpage is set.

  • Found another problem when using wpFormatAsWebpage.
    Numbers and bullets are no longer displayed, this is because the paint engine requires the paragraphs to be formatted using ReformatStd.

    Simple steps to reproduce:

    - Add to form one TWpRichText and one TWpToolbar
    - Link the toolbar and the twprichtext. Include Sel_bullets in the Sel_OutlineIcons for the toolbar
    - Set property AsWebpage to wpFormatAsWebpage on the TWpRichText
    - Run the program and click on the Sel_Bullets button on the toolbar

    I have been able to partially fix this problem by copy - pasting about 200 lines of code from ReformatStd to ReformatHTM, but this is becoming quite annoying.
    Like i said earlier it looks like ReformatStd differs completely from RefomatHTM. It is not just a different way of formatting, it is a different format routine entirely.
    ReformatSTD itself is already some 5000 lines of code. ReformatHTM is structured differently because implementation is now partially moved to the TWPLineList class, but still it seems like the new code is only a fraction of the ReformatStd code.
    So either ReformatStd has a lot of overhead, or ReformatHTM is still lacking behind on years of development.

    Again, i am very happy with the new feature. But i'm still not sure what to expect, to me it doesn't look finished yet. Is this still something you are actively developing, or just bug fixing?

  • Julian,

    If interested, i can sent you my modifications to ReformatHTM.

    We have a lot depending on the new formatting, so i am hoping for a stable release. Any clarifications from your end would be appreciated.