autofield + clear editor

  • WPTools 6.13

    Please have a look at the following code (obviously we don't have code like this but sometimes we clears the document and rebuilds it using some dynamic definitions).

    If you only do the first line (createContent) everything looks fine. If all lines are executed the style becomes broken (more so if the autofield is placed inside a cell with border and alignment for example). This problem only seems to occur for autofields. So, is there something I'm missing here (kinda urgent as the same problem occurs during printing which makes this a showstopper)?

    Regards
    patrik.nyborg(a)genicore.se

    • Offizieller Beitrag

    Hi,

    1) Please note that
    TParagraph* p(aEditor->FirstPar->AppendNewPar(true));

    actually creates 2 paragraphs if the editor was empty, cleared.

    2) TWPStoredCharAttrInterface* style(aEditor->AttrHelper());
    If you just clear it, you can use the value 0 instead.

    3) Editor->Clear();
    clears everything, including the paragraph styles, list of fonts(!) and list of colors. If you use a special font, this can be a problem. Of course it also clears all CharAttr records, so you loose the attributes in any other text which uses the same RTFProps record.

    There is a procedure ClearEx(DontClearStyles, DontResetPageSize, ResetWritingAttr) which gives You more control.

    4) what are "autofields"

  • Hi!

    1-2) Yes I'm aware of that but thanks anyway.

    3) The font used is Arial.
    If you run the example and move the cursor around, it's looks strange before (looks like subscript + fontsize=1) and after the pagenumber; are you not seeing this if you run the code?

    4) Sorry about that, autofields = text object with Name in WPTextFieldNames


    Regards
    patrik.nyborg(a)genicore.se

  • The following highlights the problem better (the top of the pagenumber is rendered inside the previous paragraph):

    Code
    void createContent(Wpctrrich::TWPRichText* aEditor) {
      aEditor->WritingAttr()->Clear();
      TParagraph* p1(aEditor->FirstPar);
      p1->Insert(0, "jjjjj", Cardinal(0));
      TParagraph* p2(p1->AppendNewPar(true));
      p2->InsertNewObject(0, wpobjTextObject, false, false, Cardinal(0))->Name = WPTextFieldNames[wpoPageNumber];
    }

    Regards
    patrik.nyborg(a)genicore.se

  • Update: this happens only for wpoPageNumber, if I use wpoNumPages everything works fine. If I replace the logic for 'PAGE' in TWPRTFEnginePaint.MeasureObject with only ResString := '1'; the layout is no longer broken (a quick trace in the original code showed that ResString was set to the empty string for the first two calls).

    Regards
    patrik.nyborg(a)genicore.se