WPCubed Product Support

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.

#1 ♥ 0
13.4k Views 2 users read 9 min
support

Hello,

The -IgnoreFont formast string is only available in the RTF reader. The HTML reader (WPIOHTML.PAS) would need some changes to do it.

YOu can comment out the calls to Attr.SetFontSize for exampe.

Julian

#2 ♥ 0

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:

procedure TppCustomWPTRichText.WPToolsForceFont(zRichText:TWPCustomRtfEdit;FontSize:integer;FontName:String);//2008-11-24 Dan Armstrong
  var par:TParagraph;//send blank for fontname or 0 for Fintsize if you want to ignore either one
      x:integer;
      zStyle:string;
      stynr: Integer;
begin
  zStyle:='CharFont:'''+FontName+''';CharFontSize:'+IntToStr(FontSize*100)+';';
  if zRichText.ParStyles.GetID('EHSA_USER')=0 then//style is not there, add it
    zRichText.ParStyles.Add('EHSA_USER').TextStyle.ASetWPSS(zStyle, false,false);
  stynr := zRichText.ParStyles.GetID('EHSA_USER');
  //det as the default
  zRichText.WritingAttr.Clear;
  if FontName<>'' then
    zRichText.WritingAttr.SetFontName(FontName);
  if FontSize>0 then
    zRichText.WritingAttr.SetFontSize(FontSize);
  //don't allow different in a paste
  if FontName<>'' then
    zRichText.ClipboardOptions:=zRichText.ClipboardOptions+[wpcoDontPasteFonts];
  if FontSize>0 then
    zRichText.ClipboardOptions:=zRichText.ClipboardOptions+[wpcoDontPasteFontSizes];
  //loop through existing data, and apply the default font/style
  par := zRichText.Memo.RTFData.FirstPar;
  while par <> nil do
    begin
      zRichText.SelectParagraph(par);
      if FontSize>0 then
        begin
          //zRichText.SelectedTextAttr.SetStyle(stynr,true,true);
          //par.SetStyle(stynr,true,true);
          //par.ClearCharAttributes(true);
          zRichText.SelectedTextAttr.SetFontSize(FontSize);
          if par.Style>0 then
            par.ASet(WPAT_CharFontSize, FontSize*100);
          //zRichT
          //zRichText.SelectedTextAttr.AGet(WPAT_CharFontSize,x);
          //zRichText.SelectedTextAttr.ASet(WPAT_CharFontSize,8);
        end;
      if FontName<>'' then
        zRichText.SelectedTextAttr.SetFontName(FontName);
      par := par.globalnext;
    end;
  zRichText.ReformatAll(true,true);
  zRichText.Repaint; //TWPRichText(Sender).Repaint;
  //zRichText.SaveToFile('c:\result.html');
end;

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?

#3 ♥ 0
support

Hi,

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

This is done like this:

procedure Form1.CreateFontAndSize(index: Integer; var ca: TWPCharAttr; param: TObject);
begin
   ca.MaskHash := ca.MaskHash and not 5; // WPAT_CharFont = bit 1, WPAT_CharSize =bit 3
end;

procedure Form1.WPToolsForceFont(WPRichText : TWPCustomRTFEdit; Size : Single; fName : String);
var i : Integer; ca : TWPCharAttr;
begin
   WPRichText.RTFData.RTFProps.Attributes.EnumCharAttr(nil, CreateFontAndSize);

   WPRichText.DefaultAttr.SetFontName(fName);
   WPRichText.DefaultAttr.SetFontSize(Size);

   // Not required for HTML saving
   WPRichText.ReformatAll(true, false);
end;

CreateFontAndSize must be an object function.

Kind Regards,

Julian

#4 ✎ ♥ 0

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

<html>
<head>
<style><!--
p.MsoNormal{mso-style-parent:'""';font-size:12.00pt;font-family:'Times New Roman';margin:0.00in;}
li.MsoNormal{mso-style-parent:'""';font-size:12.00pt;font-family:'Times New Roman';margin:0.00in;}
div.MsoNormal{mso-style-parent:'""';font-size:12.00pt;font-family:'Times New Roman';margin:0.00in;}
span.EmailStyle15{font-family:'Arial';}
.@page Section1{margin:1.00in;}
div.Section1{}

--></style></head><body>
<div><span style="font-size:11.00pt;">The investigator will construct a variety ofrecombinant replication-defective adenoviruses.<span>&nbsp;The investigator’s primary area of interest is to use the viral vectorin the study of fetal lung development.<span>&nbsp;In order to transfect the cells used in the investigations, the investigator must use the adenovirus to infect the cells, allowing for the transmission of exogenous DNA.<span>&nbsp; These viruses will carry either DNA fusion constructs capable of expressing proteins in transfected cells or DNA fusion constructs used as reporters of cloned promoter sequences.<span>&nbsp; The viruses do not have theability to replicate and carry out viral function in cells that are not transformed with an Ela oncogene.<span>&nbsp; The viruses will be produced by infection of HEK 293 cells that expresses the protein of interest.<span>&nbsp; The estimated viral concentration will be100 ml of 1.0 x 10<sup>9</sup> pfu/ml.<span>&nbsp; Rats of fetal, juvenile and adult age will be used to obtain lung tissue for primary cell culture.<span>&nbsp; In addition human fetal lung cells will be used. Cell transfections in the multiplicity of infection<span style="font-size:11.00pt;font-family:'Arial';"> <span style="font-size:11.00pt;">range<span style="font-size:11.00pt;font-family:'Arial';"> <span style="font-size:11.00pt;">of 0.1 to 500, requiring 1.0 X 10<sup>7</sup> – 5.0 X10<sup>10</sup> recombinant virus will be performed in a biological safety cabinet.<span>&nbsp; At this point, the number of various recombinant adenoviruses to be made depends on the direction of the research.<span>&nbsp; Dr. Alcorn would like a blanket approval to make several varieties, but does not anticipate more than 15 recombinant constructs.<span><br/><br/></div>
<p class="MsoNormal"><span style="font-size:10.00pt;font-family:'Arial';">This <span style="font-size:16.00pt;font-family:'Arial';">is a <span style="font-size:10.00pt;font-family:'Arial';">Test.<span>&nbsp; <br/></p>
</body></html>

Here's the html:

#5 ♥ 0
support

Hi,

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

procedure WPToolsForceFont(WPRichText : TWPCustomRTFEdit; Size : Single; fName : String);
var i : Integer;
    par : TParagraph;
begin
   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;

   // Not required for HTML saving
   WPRichText.ReformatAll(true, false);
end;

Julian

#6 ♥ 0

Julian,
I just sent you an email with a test project attached.

#7 ♥ 0
support

Dan,

it would have been good to have the test file earlier.

The problem You see comes from the embedded SPAN objects.

You can get rid of those by loading the HTML using

WPRichText2.LoadFromFile('C:\fontest.html',True,'HTML-nospanobjects');

I hope this helps,

Julian

#8 ♥ 0

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 😮ops:

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:

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:

procedure TppDBWPTRichText.LoadWPTRichText;
begin
  // Gets the text if we have a valid pipeline
  if CheckForPipelineData then
  begin
    try
      RichText := DataPipeline.GetFieldAsString(DataField);
    except
      SetRichText(ppLoadStr(414)); // Error Loading RichText
    end;
  end
  else RichText := '';

  // Give the user the chance to change the text
  inherited LoadWPTRichText;
  WPToolsForceFont(Self.WPRichText,Self.Font.Size,Self.Font.Name);//2008-11-24 
end;
#9 ♥ 0
support

Hi,

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 😮ops:

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:

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

Julian

#10 ♥ 0
This category is archived. No new posts are possible.