Recent

Author Topic: Paragraph Formatting and Syriac fonts  (Read 8782 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Paragraph Formatting and Syriac fonts
« Reply #15 on: April 01, 2017, 02:54:57 pm »
I have encounted a problem with the previously posted code. I had not tested it with setting offsets for top, bottom, left, right, and first (while using the minimum and maximum methods). Using the Multiplier method has not shown any problem.

Since I have retained the SetRangeParaParams method for top, bottom, left, right, and first... It appears that they are including the LineSpacing (which is in points for minimum and maximum methods) as a multipiler.

I am going to try to remedy this by including those parameters with the bLineSpacingRule method, which allows those values to be included with it.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Paragraph Formatting and Syriac fonts
« Reply #16 on: April 01, 2017, 06:40:33 pm »
This is a revision. I revised everything to use the same method. It seems to operate well.

Code: Pascal  [Select]
  1. procedure TCmdForm.SetOfsTop(Sender: TObject);
  2. var
  3.   pf2: ParaFormat2;
  4.   x: double;
  5.   inpOK: boolean;
  6.   err: integer;
  7.  
  8. begin
  9.   Val(OfsTop.Text, x, Err);
  10.   InpOK:= (Err=0);
  11.   if InpOK then
  12.      begin
  13.      FillChar(pf2, SizeOf(pf2), 0);
  14.      pf2.cbSize := SizeOf(PARAFORMAT2);
  15.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  16.      pf2.dwMask := PFM_SPACEBEFORE;
  17.      pf2.dySpaceBefore:= round(x*20);
  18.      SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  19.      end else if (length(OfsTop.Text)>0)
  20.                   then showmessage('Improper TOP entry.')
  21.                   else showmessage('Must enter TOP value.');
  22. end;
  23.  
  24. procedure TCmdForm.SetOfsInd(Sender: TObject);
  25. var
  26.   pf2: ParaFormat2;
  27.   x: double;
  28.   inpOK: boolean;
  29.   err: integer;
  30. begin
  31.   Val(OfsInd.Text, x, Err);
  32.   InpOK:= (Err=0);
  33.   if InpOK then
  34.      begin
  35.      FillChar(pf2, SizeOf(pf2), 0);
  36.      pf2.cbSize := SizeOf(PARAFORMAT2);
  37.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  38.      pf2.dwMask := PFM_STARTINDENT;  //PFM_STARTINDENT for absolute or PFM_OFFSETINDENT for relative to current
  39.      pf2.dxStartIndent:= round(x*20);  // note: PFM_STARTINDENT is easier to undo
  40.      SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  41.      end else if (length(OfsInd.Text)>0)
  42.                   then showmessage('Improper IND entry.')
  43.                   else showmessage('Must enter IND value.')
  44. end;
  45.  
  46. procedure TCmdForm.SetOfsLft(Sender: TObject);  // relative to PFM_STARTINDENT, ie. negative or positive,
  47. var                                             // and a zero value is flush with PFM_STARTINDENT.
  48.   pf2: ParaFormat2;
  49.   x: double;
  50.   inpOK: boolean;
  51.   err: integer;
  52. begin
  53.   Val(OfsLft.Text, x, Err);
  54.   InpOK:= (Err=0);
  55.   if InpOK then
  56.      begin
  57.      FillChar(pf2, SizeOf(pf2), 0);
  58.      pf2.cbSize := SizeOf(PARAFORMAT2);
  59.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  60.      pf2.dwMask := PFM_OFFSET;
  61.      pf2.dxOffset:= round(x*20);
  62.      SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  63.      end else if (length(OfsLft.Text)>0)
  64.                   then showmessage('Improper LFT entry.')
  65.                   else showmessage('Must enter LFT value.')
  66. end;
  67.  
  68. procedure TCmdForm.SetOfsRht(Sender: TObject);
  69. var
  70.   pf2: ParaFormat2;
  71.   x: double;
  72.   inpOK: boolean;
  73.   err: integer;
  74. begin
  75.   Val(OfsRht.Text, x, Err);
  76.   InpOK:= (Err=0);
  77.   if InpOK then
  78.      begin
  79.      FillChar(pf2, SizeOf(pf2), 0);
  80.      pf2.cbSize := SizeOf(PARAFORMAT2);
  81.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  82.      pf2.dwMask := PFM_RIGHTINDENT;
  83.      pf2.dxRightIndent:= round(x*20);
  84.      SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  85.      end else if (length(OfsRht.Text)>0)
  86.                   then showmessage('Improper RHT entry.')
  87.                   else showmessage('Must enter RHT value.')
  88. end;
  89.  
  90. procedure TCmdForm.SetOfsBtm(Sender: TObject);
  91. var
  92.   pf2: ParaFormat2;
  93.   x: double;
  94.   inpOK: boolean;
  95.   err: integer;
  96. begin
  97.   Val(OfsBtm.Text, x, Err);
  98.   InpOK:= (Err=0);
  99.   if InpOK then
  100.      begin
  101.      FillChar(pf2, SizeOf(pf2), 0);
  102.      pf2.cbSize := SizeOf(PARAFORMAT2);
  103.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  104.      pf2.dwMask := PFM_SPACEAFTER;
  105.      pf2.dySpaceAfter:= round(x*20);
  106.      SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  107.      end else if (length(OfsBtm.Text)>0)
  108.                   then showmessage('Improper BTM entry.')
  109.                   else showmessage('Must enter BTM value.')
  110. end;
  111.  
  112. procedure TCmdForm.SetOfsLns(Sender: TObject);  // multiple to base height extending down from top
  113. var
  114.   pf2: ParaFormat2;
  115.   x: double;
  116.   inpOK: boolean;
  117.   err: integer;
  118. begin
  119.   Val(OfsLns.Text, x, Err);
  120.   InpOK:= (Err=0);
  121.   if InpOK then
  122.      begin
  123.      // initialize pf2
  124.      FillChar(pf2, SizeOf(pf2), 0);
  125.      pf2.cbSize := SizeOf(PARAFORMAT2);
  126.      SendMessage(PageMemo.Handle, EM_GetParaFormat, 0, LParam(@pf2));
  127.      pf2.dwMask := PFM_LINESPACING;
  128.  
  129.      if (LnsMultiply.checked=true) then // factored descent
  130.         begin
  131.         pf2.bLineSpacingRule := 5;
  132.         pf2.dyLineSpacing:= round(x*20);
  133.         SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  134.         end;
  135.      if (LnsAtLeast.checked=true) then  // minimum ascent
  136.         begin
  137.         pf2.bLineSpacingRule := 3;
  138.         pf2.dyLineSpacing:= round(x*20);
  139.         SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  140.         end;
  141.      if (LnsExactly.checked=true) then  // maximum ascent
  142.         begin
  143.         pf2.dwMask := PFM_LINESPACING;
  144.         pf2.bLineSpacingRule := 4;
  145.         pf2.dyLineSpacing:= round(x*20);
  146.         SendMessage(PageMemo.Handle, EM_SETPARAFORMAT, 0, Longint(@pf2));
  147.         end;
  148.      end else if (length(OfsLns.Text)>0)
  149.                  then showmessage('Improper LNS entry.')
  150.                  else showmessage('Must enter LNS value.')
  151. end;  
  152.  

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

Thaddy

  • Hero Member
  • *****
  • Posts: 9189
Re: Paragraph Formatting and Syriac fonts
« Reply #17 on: April 01, 2017, 09:27:15 pm »
I would suggest the following, but it is a matter of taste:
Code: Pascal  [Select]
  1. // FillChar(pf2, SizeOf(pf2), 0);
  2. pf2 := Default(Paraformat2);
Default() is a compiler intrinsic introduced in FPC 3.0.0. It zero's the memory for the size of the underlying type.
« Last Edit: April 01, 2017, 09:31:07 pm by Thaddy »
also related to equus asinus.

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Paragraph Formatting and Syriac fonts
« Reply #18 on: April 03, 2017, 07:12:40 pm »
Thaddy,

Thanks for the input. Unfortunately, I am using FPC 2.4.4. FPC 3.0.0 still has problems with Windows XP.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit