Recent

Author Topic: Richmemo SetTextAttributes  (Read 15729 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Richmemo SetTextAttributes
« on: July 28, 2016, 08:48:38 pm »
I am using RichMemo. By the sample project you change text attributes as follows...

procedure TCmdForm.btnUnderlineClick(Sender: TObject);
begin
  if PageControl1.PageCount>0 then
     begin
     if (fsUnderline in SelFontFormat.Style = False)
        then SelFontFormat.Style:= SelFontFormat.Style + [fsUnderline]  // toggle on
        else SelFontFormat.Style:= SelFontFormat.Style - [fsUnderline]; // toggle off
     PageMemo.SetTextAttributes(PageMemo.SelStart, PageMemo.SelLength, SelFontFormat);
     end;
end;

But if it is mixed formatting it does the underline but also sets color, font, size, etc. to whatever the last attributes are in the selection. I think the command should be SetRangeParams instead of SetTextAttributes, but it uses a ModifyMask, and I don't don't know how to apply it... no documentation.

Can anyone help?

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #1 on: July 28, 2016, 09:45:49 pm »
you're right. If you want to preserve the styles that are already in the text range, you should use SetRangeParams.

I've updated the documentation, please let me know, if it's clear enough and you know what needs to happen.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #2 on: July 28, 2016, 10:41:10 pm »
skalogryz,

Thank you for your prompt response. I will study the material you have posted.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #3 on: July 29, 2016, 06:45:24 pm »
skalogryz,

The following method worked without flaw for setting color,
font, and size without disturbing existing formats.

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.btnTextColorColorChanged(Sender: TObject);
  2. var ChgColor: integer;
  3. begin
  4.   if PageControl1.PageCount>0 then
  5.      begin
  6.      ChgColor:= btnTextColor.ButtonColor;
  7.      RichMemo1.SetRangeParams (RichMemo1.SelStart,
  8.                              RichMemo1.SelLength,
  9.                              [tmm_Color],
  10.                              '',
  11.                              0,  
  12.                              ChgColor,
  13.                              [],
  14.                              []  
  15.                              );
  16.      RichMemo1.SetFocus;
  17.      end;
  18. end;
  19.  

But when I attempted the following for font styles I got irratic results.
If it was mixed fonts, colors, and styles... the first character was made
bold, but was also assigned the full styles of the last character selected.
All others in the selection were made bold, and kept their font, size, but
had the color of the last character. The issues are only with tmm_Styles.

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.btnBoldClick(Sender: TObject);
  2. var Xbeg,Xrun: longint;
  3. begin
  4.   Xbeg:= RichMemo1.SelStart;
  5.   Xrun:= RichMemo1.SelLength;
  6.   if PageControl1.PageCount>0 then
  7.      begin
  8.      if (fsBold in SelFontFormat.Style = False)
  9.         then begin
  10.              RichMemo1.SetRangeParams (Xbeg,
  11.                                       Xrun,
  12.                                       [tmm_Styles],
  13.                                       '',
  14.                                       0,
  15.                                       0,
  16.                                       [fsBold], // add bold
  17.                                       []
  18.                                       );
  19.              end
  20.         else begin
  21.              RichMemo1.SetRangeParams (Xbeg,
  22.                                       Xrun,
  23.                                       [tmm_Styles],
  24.                                       '',
  25.                                       0,
  26.                                       0,
  27.                                       [],
  28.                                       [fsBold] // remove bold
  29.                                       );
  30.              end;
  31.      RichMemo1.SetFocus;
  32.      end;
  33. end;
  34.  

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #4 on: July 29, 2016, 07:01:46 pm »
But when I attempted the following for font styles I got irratic results.
If it was mixed fonts, colors, and styles... the first character was made
bold, but was also assigned the full styles of the last character selected.
All others in the selection were made bold, and kept their font, size, but
had the color of the last character. The issues are only with tmm_Styles.
What's the operating system/widgetset you're using?

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #5 on: July 29, 2016, 07:35:17 pm »
I am operating on Windows XP Pro, version 2002, service pack 3, laz version 1.4.4, fpc version 2.6.4, svn revision 49931, i386-win32 - win32/win64

I am not using the new laz/fpc version because it has bugs... or doesn't work right with XP.

Rick
« Last Edit: July 29, 2016, 07:51:26 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #6 on: July 29, 2016, 07:55:19 pm »
what's RichMemo revision you're using?

Is it possible for you to provide RTF that exhibits the error.


Nevermind. I can see the issue when the style is removed.
« Last Edit: July 29, 2016, 07:57:38 pm by skalogryz »

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #7 on: July 29, 2016, 08:04:35 pm »
For what it is worth it is the Trunk Version. Attached is the RTF.

Rick
« Last Edit: July 29, 2016, 08:15:11 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #8 on: July 29, 2016, 08:47:38 pm »
Trunk is updated. r5049 should handle the issue for you.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #9 on: July 29, 2016, 09:29:25 pm »
I searched for r5049 but got r5050. It was also in a format that I am not sure as to what I am looking at... two parallel versions, but I don't know which is the new version.

Do you have a direct link for downloading?

Rick
« Last Edit: July 29, 2016, 09:37:12 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #10 on: July 29, 2016, 09:38:06 pm »
r5050 should work as well. (the number is incremental for trunk, thus updating to 5050 also delivers 5049 for you)

There's a direct link, but it's updated on nightly basis and currently has an earlier version.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #11 on: July 29, 2016, 09:58:18 pm »
skalogryz,

Thank you for your assistance.

I look for the download in a day or two.

I also have a question about paragraph offsets. I have copy/pasted your rtf into several editors, and also loaded your files into them. All of them can read your format. But when I use RichMemo to read their formats, yours is not translating their paragraph offsets. If I copy/paste them into RichMemo, it formats theirs properly. I think Windows is doing the work for you. Then when I read their offsets you show exaggerated units, and it then reformats the paragraph as if it is by your units. I think it needs to recognize their measuring units and convert them to your native values. Is that possible?

Rick

Rick.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Richmemo SetTextAttributes
« Reply #12 on: July 29, 2016, 10:08:36 pm »
I'm not quite sure what offsets you're referring to. Please provide examples.

Form my end, please see attachments. The RTF you sent earlier opened in MS Word and application from "paragraphs" sample.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #13 on: July 30, 2016, 12:17:25 pm »
Paragraph offsets are Top, Bottom, Indent, Head, Tail, and Linespace.

But in the process of getting figures for you I discovered that the file I had been experimenting on had become corrupted. When I built a new file to work with I found that the offset issue did not exist.

Sorry to trouble you with a goose chase that is my fault.

Rick 
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Richmemo SetTextAttributes
« Reply #14 on: July 30, 2016, 03:20:56 pm »
skalogryz

I installed your 5051 revision. SetRangeParams is now working properly as to the issue I had raised. Now I notice another.

With the following method for using SetRangeParams, something is not happening internally within SetRangeParams. After modifying the Styles, I am assuming that there is a global variable for the selection content, and it is not updating that variable. So the toggle method that I am employing cannot toggle the Bold selection back and forth. I have to manually reselect the text in order to toggle the style on or off. It is only happening with tmm_Styles.

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.btnBoldClick(Sender: TObject);
  2. begin
  3.   if PageControl1.PageCount>0 then
  4.      begin
  5.      if (fsBold in SelFontFormat.Style = False)
  6.         then begin // not in
  7.              Richmemo1.SetRangeParams (Richmemo1.SelStart,  //  int: begin position of selection, 0 sets start of file.
  8.                                      Richmemo1.SelLength,  //  int: length of selection characters, -1 sets end of file.
  9.                                      [tmm_Styles],        //  cst: modify types, [] sets to empty, or [tmm_Styles,tmm_Color]
  10.                                      '',                  //  str: font name, '' sets to empty.
  11.                                      0,                   //  int: font size, 0 sets to empty.
  12.                                      0,                   //  int: color, 0 sets to empty.
  13.                                      [fsBold],            //  cst: adding styles, [] sets to empty, or [fsBold,fsItalic]
  14.                                      []                   //  cst: remove styles, [] sets to empty, or [fsBold,fsItalic]
  15.                                      );
  16.  
  17. showmessage('Made it Bold'); // test for proving entry
  18.  
  19.              end
  20.         else begin  // is in
  21.              Richmemo1.SetRangeParams (Richmemo1.SelStart,  //  int: begin position of selection, 0 sets start of file.
  22.                                      Richmemo1.SelLength,  //  int: length of selection characters, -1 sets end of file.
  23.                                      [tmm_Styles],        //  cst: modify types, [] sets to empty, or [tmm_Styles,tmm_Color]
  24.                                      '',                  //  str: font name, '' sets to empty.
  25.                                      0,                   //  int: font size, 0 sets to empty.
  26.                                      0,                   //  int: color, 0 sets to empty.
  27.                                      [],                  //  cst: adding styles, [] sets to empty, or [fsBold,fsItalic]
  28.                                      [fsBold]             //  cst: remove styles, [] sets to empty, or [fsBold,fsItalic]
  29.                                      );
  30.  
  31. showmessage('Removed Bold');  // test for proving entry
  32.  
  33.              end;
  34.      Richmemo1.Repaint;
  35.      Richmemo1.SetFocus;
  36.      end;
  37.  

Rick
« Last Edit: July 31, 2016, 12:06:08 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

 

TinyPortal © 2005-2018