Font mapping with LoadFromString

  • I have a WPRichText where f0 (default font) is set to Arial and f1 is set to Times New Roman. I know about the -nodefaultfont option, but please read thru.. I hope I explain this clearly.

    I Issue two LoadFromStrings, the first has a default font of Times New Roman and the 2nd has a default font of Arial:

    Loaded via: pWP.LoadFromString(vWP.AsANSIString('WPTOOLS'), 'WPTOOLS');

    Keep in mind that all the text is marked to be Times New Roman, so it might be f0 or f1 depending on the font table.

    The first LoadFromString results in the new text (f0 in its font table is Times New Roman) as showing in Times New Roman and the font table now has the default font as Times New Roman instead of Arial.

    When I load the 2nd one which has a default font of Arial and f1 as Times New Roman, the font table is switched back to a default font of Arial and as such the first loaded text switches to Arial.

    Not good since everything should be in Times New Roman. So I add the option -nodefaultfont for the LoadFromString:

    pWP.LoadFromString(vWP.AsANSIString('WPTOOLS'), 'WPTOOLS,-nodefaultfont');

    The first LoadFromString is wrong right away. It shows as Arial because the font table has f0 as Arial (the string being loaded has the default as Times New Roman, but that option doesn't change the font table).

    Is there an option that will not touch the host WPRichText's font table (but add to it if needed) and remap the fonts from the one being loaded? In other words, I need an option that will see that the WPRichText being loaded has a default font of Times New Roman and will only add to and/or remap the text to the existing font table so that it stays Times New Roman? i.e. if the host has Times New Roman as f1, then f0 in the loaded WPRichText gets reassigned as f1?

    One more thing to note. The Loaded text does not have an actual font assigned to the text whereas the original text does, so it gets remapped to the new font table and the loaded text does not.

    I hope that was clear.

    Einmal editiert, zuletzt von ehimmer (5. September 2020 um 21:54) aus folgendem Grund: Added one additional note about original text having an actual font assignment and the loaded text does not.

    • Offizieller Beitrag

    f0 just means the font with index 0. It is always remapped to the fonts which are used in the editor.

    So the loaded font does not necessarily get the index 0.

    I also assume your text defines a font - so usually this font is loaded. You cannot expect that a font gets number 0, that happens dynamically.

    I assume you want the loaded text to have the standard font of your text.

    You can use -IgnoreFonts and -IgnoreFontSize

  • I tried ignoreFonts and that just made things worse in other situations because it truly ignored the loaded text fonts. Where I am having an issue is where the text being loaded has no font index assigned to it, so it appears to use the default font 0 index. When loaded and since it has no font index assigned, it takes on the receiving end's font 0 when I use the -nodefaultfont. If I don't use that option, it changes the font table and toggles other text that also does not have a font index assigned to it if f0 was replaced by the loaded text. Text that has a font index assigned gets updated to reference the correct new index.

    Is there a way to force all text to have a font index assigned to it? I could apply this before doing the LoadFromString.

    The process I use is I create a temp WPRichText, LoadFromStream fromthe database into the temp WPRichText and then do a LoadFromString into the main WPRichText. There are reasons I don't go directly into the main WPRichText that I won't get into (other than to say I clone linked images and rename duplicates) but I could use that temp WPRichText to force a font index selection to any text that doesn't have one assigned.

    Einmal editiert, zuletzt von ehimmer (6. September 2020 um 18:03)

  • Sorry, I thought it was obvious. I do not want the font to change when using LoadFromString. If the font in the WPRichText is Times New Roman, it should be Times New Roman when added to the main WPRichText and should not change the font of any existing text in the host WPRichText. My example tries to show that using or not using the -nodefaultfont causes both of this to occur and can make things worse depending on the circumstances.

    This font changing is a disaster for us. This did not occur in WPTools5 but both of our beta testers have run into this font changing issue with our new version using WPTool 9.1. In my example I tried to solve the problem using -nodefaultfont but doesn't help.

    So the problem I need to solve to how to keep the font from changing with LoadFromString. It only seems to occur if the text is defaulting to using f0 when it doesn't have any specific font index selection. That is the problem that needs to be solved. It should be assigned one when using LoadFromString or something I can do to make it have a a font index selection prior to the LoadFromString so that the font table doesn't change which can cause other text that has no specific font index assigned to suddenly changes to a different font should f0 represent a different font than it was prior to the LoadFromString.

    If the host WPRichText has f0 as Arial and f1 as Times New Roman. How do I use LoadFromString which is loading a WPRIchText where the text has not specific font index associated to it? Currently it just then uses f0 which is Arial, but in the WPRichText being loaded f0 was Times New Roman. So after the LoadFromString it is now Arial but should be Times New Roman.

    If I do not use -nodefaultfont, then it sort of works but the font table changes but should not, IMHO. Instead the text that has no font index should have one added to it that indexes the correct font, and adds that font to the table if missing.

    With all that being said. I did an experiment...

    In a normal procedure, a user will export their comments from the old version that uses WPTools5 and import them into our new version that uses WPTools9. Many of these exported comments do not have a specific font index assigned. In only those cases, it ends up using f0 which is Times New Roman. These are the ones that have the problem and cause the font changing issue I need solved.

    Now what I tried was to then use the old version to import them in and export them once more for import into our new version. Somehow, all those comments that did not have a specific font index now do. And the problem is solved. So whatever WPTools5 did to solve assigning a font index to text that has none is what I need to be able to do within WPTools9.

    Example:

    This is what WPTools9 ends up with in a typical export/import from WPTools5 into WPTools9:

    Code
    {\*\bkmkstart $linked:<all>}\cf0 There was no kickout flashing details observed at the lower bottom edges of the roof lines interfaces and the sidewalls that continues past the edges of the roofs.  The lack of this kickout flashing may and will most likely allow water to penetrate at these points.{\*\bkmkend $linked:<all>}

    Font Table which makes the text Times New Roman even though no font index is present:

    Code
    {\fonttbl{\f0\fnil\fcharset1 Times New Roman;}{\f1\fnil\fcharset2 Symbol;}

    This is what WPTools9 ends up with after my experiment where I import the re-exported comments:

    Code
    {\*\bkmkstart $linked:<all>}\f1\cf0 There was no kickout flashing details observed at the lower bottom edges of the roof lines interfaces and the sidewalls that continues past the edges of the roofs.  The lack of this kickout flashing may and will most likely allow water to penetrate at these points.{\*\bkmkend $linked:<all>}

    Font table:

    Code
    {\fonttbl{\f0\fnil\fcharset1 Arial;}{\f1\fnil\fcharset1 Times New Roman;}{\f2\fnil\fcharset2 Symbol;}

    Notice that the text "There was no kickout..." now has a font index assigned to it (f1) whereas before it did not. Having that f1 (which references Times New Roman) is key. Also, the font table was been updated but the text is still Times New Roman. So somehow it properly updated the font table by adding Times New Roman as f1 and added the font index to the text. WPTools9 is not doing this for text with no previous font index assignment.

    Einmal editiert, zuletzt von ehimmer (7. September 2020 um 15:55)

    • Offizieller Beitrag

    WPTools standardizes text which is using the default font. This is because otherwise it would not be possible to change that default style later and see updated text.

    If you do not want this use the compiler symbol

    DONT_FIX_DEFSTYLE

    Either in the options of your program or in WPINC.INC.

    You can also use the option -DontFixAttr in the formatstr option of the Load...() function.

    vWP.LoadFromStream(vMStream, 'RTF-DontFixAttr');

  • Thanks, that seems to do the trick! Sorry for the long narrative. I'm used to other developers needing detailed scenarios to fully understand the issue and sometimes my explanations just makes it worse.