I want to ignore font size

  • I collect info In HTML from end-users (online, so In a non-wpRichtext component in which I don't have control over font size), and I run a report using report Builder ppWPRichtext. For the report only, to save space ansnd have consistent format, I'd like to ignore the font size specified in the HTML. Is there a simple property setting I can set to ignore fontsize (whether done with style or otherwise), I do I need to loop through styles/attributes? Anyone have an example? Thanks.

  • In my first attempt at this I added my own options to the WPIOHTML unit, but the results were inconsistent. I abandoned that, and tried the approach of iteration through the paragraphs, but I think that method is really for RTF format, and not for HTML. How can I iterate through each tag in the HTML?

    Here's the code for the paragraphs, but I think b/c some paragraphs have several tags, some of the fonts get missed, still showing the larger font. (I'm trying to make them respect the font set in the ReportBuilder dialog properties of the TppDBWPTRichText so at the end of TppDBWPTRichText.LoadWPTRichText, I call:
    ...inherited LoadWPTRichText;
    WPToolsForceFont(Self.WPRichText,Self.Font.Size,Self.Font.Name);//2008-11-24
    end;

    Then, here's the procedure:


    To sum up, I want to do the same thing, but I want to do it tag-by-in the html, as opposed to par-by-par. Does that make sense?

    • Offizieller Beitrag

    Hi,

    the quickes way would be the elimination of the attributes from the character attribute cache.

    This is done like this:

    CreateFontAndSize must be an object function.


    Kind Regards,

    Julian

  • Here's the results, I'm trying to force smaller font (8pt), and I'm still seeing some of it in larger type:

    Here's the html:

    • Offizieller Beitrag

    Hi,

    to also clean the paragraphs and styles (MS Word import yuck) use this


    Julian

  • My apologies, I thought I had sent the test html already, because, I did, but it was in the 10/3 email about the superscript/subscript tags. Sorry about that :oops:

    Here's the procedure, I added a part to add the -nospanobjects to the format. In the test project, I had to re-load it using stream to get the format to take effect (is there already a procedure to do this?), and it would not work unless the textloadformat is explicitly set to HTML to begin with (if 'AUTO' it wouldn't work), However in the ppWPTools unit, it does work, even when the format is 'AUTO'. Not sure why. I'm pasting the code, in case you have anny suggestions as far as improvements or best practices go:

    Code
    procedure TppCustomWPTRichText.WPToolsForceFont(WPRichText : TWPCustomRTFEdit; Size : Single; fName : String);var i : Integer;    ca : TWPCharAttr;    par : TParagraph;    sAddToFormat:String;    zStream:TMemoryStream;begin  sAddToFormat:='';  if (Pos('-nospanobjects',WPRichText.TextLoadFormat)=0) then    begin//add this to the load format, if not already there, then reload      if (Pos('-',WPRichText.TextLoadFormat)<>0) then        sAddToFormat:=sAddToFormat+',';      sAddToFormat:=sAddToFormat+'-nospanobjects';      zStream:=TMemoryStream.Create;      try        WPRichText.SaveToStream(zStream,WPRichText.TextLoadFormat);        zStream.Position:=0;        WPRichText.TextLoadFormat:=WPRichText.TextLoadFormat+sAddToFormat;        WPRichText.Clear;        WPRichText.LoadFromStream(zStream);      finally        zStream.Free;      end;    end;   WPRichText.RTFData.RTFProps.Attributes.EnumCharAttr(nil, CreateFontAndSize);   WPRichText.DefaultAttr.SetFontName(fName);   WPRichText.DefaultAttr.SetFontSize(Size);   par := WPRichText.RTFData.FirstPar;   while par<>nil do   begin      par.ADel(WPAT_CharFont);      par.ADel(WPAT_CharFontSize);      par := par.next;   end;   for i:=0 to WPRichText.ParStyles.Count-1 do   begin       WPRichText.ParStyles[i].TextStyle.ADel(WPAT_CharFont);       WPRichText.ParStyles[i].TextStyle.ADel(WPAT_CharFontSize);   end;   //WPRichText.ReformatAll(true, false);// Not required for HTML savingend;

    Here's where I call it in ppWPTools:

    • Offizieller Beitrag

    Hi,

    Zitat

    My apologies, I thought I had sent the test html already, because, I did, but it was in the 10/3 email about the superscript/subscript tags. Sorry about that :oops:


    Your account name here is different to your name You use for e-mails.

    Do I read your post correctly, that it now works. Or are there problems remaining.

    To work when rendering a report I would call that procedure also in DimensionRichtext - see mail mail.

    The "-nospanobjects" should be added to the first call to LoadFromStream, I would say here:

    Code
    procedure TppCustomWPTRichText.LoadFromStream(aStream: TStream);
    begin
      FPaintEngine.RTFData.Clear;
      FPaintEngine.RTFData.LoadFromStream(aStream)
      //InvalidateDesignControl;
    end;

    Julian