Recent

Author Topic: Paragraph Formatting  (Read 2082 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Paragraph Formatting
« on: August 24, 2016, 06:34:52 pm »
I am using the following two methods to format paragraphs.

Code: Pascal  [Select]
  1. procedure TCmdForm.FormatUpdClick(Sender: TObject);
  2. begin
  3.   if TopChanged then SetOfsTop(self);
  4.   if IndChanged then SetOfsInd(self);
  5.   if LftChanged then SetOfsLft(Self);
  6.   if LnsChanged then SetOfsLns(Self);
  7.   if RhtChanged then SetOfsRht(Self);
  8.   if BtmChanged then SetOfsBtm(Self);
  9.   if DirChanged then
  10.      if btnLTR.checked
  11.         then MakeRTLPara(PageMemo,false)  // LTR: Anglo
  12.         else MakeRTLPara(PageMemo,true);  // RTL: Semitic
  13.   TopChanged:= false;
  14.   IndChanged:= false;
  15.   LftChanged:= false;
  16.   LnsChanged:= false;
  17.   RhtChanged:= false;
  18.   BtmChanged:= false;
  19.   DirChanged:= false;
  20. end;
  21.  
  22. procedure TCmdForm.SetOfsTop(Sender: TObject);
  23. var
  24.   m: TParaMetric;
  25.   x: double;
  26.   inpOK: boolean;
  27.   err: integer;
  28. begin
  29.   InitParaMetric(m);
  30.   Val(OfsTop.Text, x, Err);
  31.   InpOK:= (Err=0);
  32.   if InpOK then
  33.      begin
  34.      x:= round(x);
  35.      m.SpaceBefore:= x;
  36.      PageMemo.SetRangeParaParams(PageMemo.SelStart, PageMemo.SelLength, [pmm_SpaceBefore], m);
  37.      end else if (length(OfsTop.Text)>0)
  38.                   then showmessage('Improper value entry.')
  39.                   else showmessage('Must enter value.');
  40. end;  
  41.  

It is time consuming on a large file, since it sets each parameter one at a time for the list of paragraphs. Is there a way to set multiple parameters with one call to... PageMemo.SetRangeParaParams(PageMemo.SelStart, PageMemo.SelLength, [pmm_SpaceBefore], m);

Rick
« Last Edit: August 24, 2016, 06:50:17 pm by rick2691 »
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: Paragraph Formatting
« Reply #1 on: September 01, 2016, 03:45:42 am »
It is time consuming on a large file, since it sets each parameter one at a time for the list of paragraphs. Is there a way to set multiple parameters with one call to... PageMemo.SetRangeParaParams(PageMemo.SelStart, PageMemo.SelLength, [pmm_SpaceBefore], m);
Yes there's. Instead of passing a single flag in the set of modified flags, you could pass all of them togere:
Code: Pascal  [Select]
  1. PageMemo.SetRangeParaParams(PageMemo.SelStart, PageMemo.SelLength,
  2.  [pmm_FirstLine
  3.   ,pmm_HeadIndent
  4.   ,pmm_TailIndent
  5.   ,pmm_SpaceBefore
  6.   ,pmm_SpaceAfter
  7.   ,pmm_LineSpacing]
  8.   , m)
  9.  
However, please makes sure that all fields of m record are populated as expected.

Also you might want to consider using SetParaMetric method, instead of SetRangeParaParams. The later is looping through paragraphs only changing the desired parameters, which might be a time consuming.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz