ConvertSymbolFonts and bullets

General TRichView support forum. Please post your questions here
Post Reply
whisper1980
Posts: 28
Joined: Sun May 25, 2025 6:41 pm

ConvertSymbolFonts and bullets

Post by whisper1980 »

Using the evaluation trial (TRichViewEdit v23.1) under Delphi 12.3. Sorry for the long post.

The bullet I use is from the Symbol set, character B7.
Checkboxes and radio buttons use Wingdings:
CmtChkBox_Empty = 168; // 0xA8
CmtChkBox_Check = 254; // 0xFE
CmtRadioBtn_Empty = 161; // 0xA1
CmtRadioBtn_Check = 164; // 0xA4

RTFOption.rvrtfDuplicateUnicode is False.

See "SymbolSet.rtf" for sample RTF that I load using your Editor 1 demo, RVEditDemo_Skia, at:
C:\Components\TRichViewTrialDelphiFMX_D12\TRichView\Demos\Delphi.FMX\Editors\Editor 1

When RTFReadProperties.ConvertSymbolFonts is False, bullets, checkboxes, radio buttons show up fine on Windows. On Android, bullets show up fine, though tiny, but not checkboxes and radio buttons. See "SymbolSet Windows.jpg" and "SymbolSet Android.jpg".

When RTFReadProperties.ConvertSymbolFonts is True, checkboxes, radio buttons show up fine on Windows, but not bullets (double char kind of thing). On Android, bullets come out like they do on Windows (double char thing). Checkboxes and radio buttons are better but not good. Unchecked radio button looks good, but not the checked version. For checkboxes, checked and unchecked are both checked. See "SymbolSet Win Convert.jpg" and "SymbolSet Android Convert.jpg".

I even tried deploying Wingdings as both wingding.ttf and Wingdings.ttf to ".\assets\internal" for the Android build, but not sure if I even came close to doing that right.

My main concern is the bullets when ConvertSymbolFonts is True for Android and iOS (my app is only for mobile). For checkboxes and radio buttons I'm thinking/hoping maybe I can find alternative chars that convert better if I can't get my current Wingding chars to work.

Any help or insight is most welcome! Thanks!
Eric
Attachments
SymbolsSet Android Convert.jpg
SymbolsSet Android Convert.jpg (54.16 KiB) Viewed 11159 times
SymbolsSet Android.jpg
SymbolsSet Android.jpg (51.43 KiB) Viewed 11159 times
SymbolsSet Windows.jpg
SymbolsSet Windows.jpg (8.44 KiB) Viewed 11159 times
SymbolsSet Win Convert.jpg
SymbolsSet Win Convert.jpg (8.86 KiB) Viewed 11159 times
SymbolSet.rtf
(3.26 KiB) Downloaded 119 times
whisper1980
Posts: 28
Joined: Sun May 25, 2025 6:41 pm

Re: ConvertSymbolFonts and bullets

Post by whisper1980 »

I found an issue with the RTF, which is generated by WPTools for the most part. However, not sure why it is not a problem when ConvertSymbolFonts is false but is when true.

In the SymbolSet.rtf, there is this line:
{\list\listtemplateid2\listsimple{\listlevel\leveljc0\levelfollow0\levelstartat1\levelindent360\levelnfc23\levelstartat1{\leveltext\'02·\'00;}{\levelnumbers \'02;}\f4}\listid2}

If I change the two '02 to '01 (or even just the first one), the bullets come out fine when using ConvertSymbolFonts:
{\list\listtemplateid2\listsimple{\listlevel\leveljc0\levelfollow0\levelstartat1\levelindent360\levelnfc23\levelstartat1{\leveltext\'01·\'00;}{\levelnumbers \'01;}\f4}\listid2}

It shouldn't be '02 since a bullet is one char. I'm no expert on RTF by a long shot, but am I wrong? If I'm not wrong, it seems like a bug in WPTools RTF export that I can probably fix, but again, why is it OK when not using ConvertSymbolFonts?

Eric
Sergey Tkachenko
Site Admin
Posts: 17857
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ConvertSymbolFonts and bullets

Post by Sergey Tkachenko »

\leveltext\'02·\'00 defines a two-character string. The first character is '·', the second character is a placeholder for the list counter.
However, for this list, \levelnfc23 is set, that means "Bullet" (no list counter).
While this is bug of this RTF, I'll change RTF reading code to remove list counter placeholders for bullers.
whisper1980
Posts: 28
Joined: Sun May 25, 2025 6:41 pm

Re: ConvertSymbolFonts and bullets

Post by whisper1980 »

I now have the registered version, and I noticed an odd thing in the header for bullets that has a %s in it, which seems a bit off. Example (typed from a screen shot, so there may be typos):

Code: Select all

{listlevel\levelnfc23\leveljc0\li360\fi-360\jclisttab\tx360{\leveltext\'03\bullet %s;}
Is this expected? Seems like an unresolved Format tag.

Eric
Sergey Tkachenko
Site Admin
Posts: 17857
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ConvertSymbolFonts and bullets

Post by Sergey Tkachenko »

TRichView uses format strings with "%s" placeholders for list text (RVStyles.ListStyles[].Levels[].FormatString).
However, it is expected that "%s" placeholders are used only in FormatStrings for numbered list types (like decimal, Roman, etc.), not for bullets.
So, for bullets, TRichView saves FormatStrings in RTF as they are.

So, the problem is not in RTF saving. The problem is in the code that adds "%s" to FormatString.

As I said before, TRichView RTF-reading code does not expect that number placeholders are inserted for bullets. MS Word and Wordpad never do it, but this problem exists in your RTF sample.

Quick fix: open RVRTF.pas (if you use VCL/Lazarus version of TRichView) and change the implementation of procedure ConvMarker97 to:

Code: Select all

procedure ConvMarker97(Reader: TCustomRVMSWordReader; RTFMarker: TRVRTFListLevel97;
  out RVType: TRVListType; out FormatStr1, FormatStr2: TRVUnicodeString;
  out FontName: TFontName; out Charset: TRVFontCharset; ConvertSymbolFonts: Boolean);
var
  i:      Integer;
  s1, s2: TRVUnicodeString;
begin
  if RTFMarker.Graphic <> nil then
    RVType := rvlstPicture
  else
    case RTFMarker.ListType of
      rtf_pn_Decimal, rtf_pn_Default:
        RVType := rvlstDecimal;
      rtf_pn_LowerLetter:
        RVType := rvlstLowerAlpha;
      rtf_pn_UpperLetter:
        RVType := rvlstUpperAlpha;
      rtf_pn_LowerRoman:
        RVType := rvlstLowerRoman;
      rtf_pn_UpperRoman:
        RVType := rvlstUpperRoman;
      rtf_pn_DecimalLeadingZero:
        RVType := rvlstDecimalLeadingZero;
      else //rtf_pn_Bullet:
        RVType := rvlstBullet;
    end;
  FormatStr1 := RTFMarker.Text;
  FormatStr1 := RVCopyW(RTFMarker.Text, RVStrLow() + 1);
  FormatStr2 := FormatStr1;
  for i := RVStrHighW(FormatStr1) downto RVStrLow() do
    if FormatStr1[i] <= #9 then
    begin
      if RVType <> rvlstBullet then
      begin
        s2 := '%' + RVIntToStrW(ord(FormatStr1[i])) + ':s';
        if FormatStr1[i] = #0 then
          s1 := '%s'
        else
          s1 := s2;
      end
      else
      begin
        s1 := '';
        s2 := '';
      end;
      RVDeleteW(FormatStr1, i, 1);
      RVInsertW(s1, FormatStr1, i);
      RVDeleteW(FormatStr2, i, 1);
      RVInsertW(s2, FormatStr2, i);
    end;
  FontName := RVU_UnicodeToUIString(Reader.GetMarkerFontName(RTFMarker));
  Charset := Reader.GetMarkerCharset(RTFMarker);
  if ConvertSymbolFonts and RV_IsKnownSymbolFont(FontName) then
  begin
    FormatStr1 := RV_MakeKnownSymbolFontStr2W(FormatStr1, FontName);
    FormatStr2 := RV_MakeKnownSymbolFontStr2W(FormatStr2, FontName);
    Charset := ANSI_CHARSET;
    FontName := RVDefaultLoadProperties.DefaultBulletFontName;    
  end;
end;
This update removes number placeholders from bullets when loading RTF files.
whisper1980
Posts: 28
Joined: Sun May 25, 2025 6:41 pm

Re: ConvertSymbolFonts and bullets

Post by whisper1980 »

I'm using the FMX version of TRichView.

I use WPTools in our Windows app and I have to convert things that WPTools uses in its RTF to be compatible with TRichView when we transfer data to our mobile companion app that is now going to use TRichView (instead of that HTML editor) for use by home inspectors to easily enter their findings. On the return trip back to our Windows app, I have to translate things back to RTF that is compatible with WPTools. I found that if I modified a comment on mobile that contained bullets, that I could not do a straight conversion back again like for those comments that were not modified. That's when I noticed the bullet %s thing. Normally it wouldn't matter in TRichView I suppose, but it does when I have to convert things back for WPTools. I thought maybe it was some oversight that needed to be fixed, so no big deal. I'll just remove the bullet %s string from the RTF. Going forward I'll just make a note to check if anything changed when updating TRichView to make sure I can convert bullets back again properly.

I also noticed that your using of the \u# for unicode chars does not have the fallback char in it, like "\u123456 ?". I thought that fallback char was mandatory. You use just "\u123456 ". One of those things I have to watch out for on conversion back.

One last thing. I decided not use use the option ConvertSymbolFonts since it didn't give the substitution that I wanted (maybe its the chars I chose), and was able to get Wingdings to work on an older Android test phone, Samsung S7 using Android 8, simply by deploying it. This does not work on newer Android phones, like my S21 using Android 15, or on iOS. Even failed on iOS when I used Settings > General > Fonts to install Wingdings. I even tried your suggestions in that example post of yours about using custom fonts, but no luck. I only use Wingdings for checkboxes and radio buttons, and Symbol for bullets, and found characters that will sort of work OK in the default font. I'll get back to fonts later, but It'll do for now.

But anyway... I love how TRichView works, seems solid... and cross platform!!. WPTools is a bit buggy and I have had to modify their source code far too much. If I had the time I would love to replace WPTools in our main Windows app with TRichView and not have to do all this translating back and forth.

Thanks again for all your help in getting me up to speed on TRichView.
Sergey Tkachenko
Site Admin
Posts: 17857
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ConvertSymbolFonts and bullets

Post by Sergey Tkachenko »

I also noticed that your using of the \u# for unicode chars does not have the fallback char in it, like "\u123456 ?". I thought that fallback char was mandatory.
Fallback chars are optional. If you need them, include rvrtfDuplicateUnicode in RTFOptions property.
These characters are useful if this RTF will be read by an application that does not understand Unicode characters in RTF. Otherwise, they only increase file size.
Post Reply