Skip to main content
Known Participant
January 20, 2010
Question

FDK: Bold Text not being applied to certain sentences

  • January 20, 2010
  • 1 reply
  • 3285 views

Hi there

A customer of ours using our document localisation package has reported an issue where some bold formatting

is not being applied to certain parts of sentences. Using the Visual Studio 2008 debugger, we seem to be doing everything right.

We create a F_TextRangeT object which represents the text we want to apply the formatting to.

Then we create a F_PropValsT structure which contains the formatting for this text range.

I also check the value of FA_errno before and after the application of formatting properties and it is always zero,

so Frame is detecting anything erroneous either.


Finally , we apply these properties using F_ApiSetTextProps(m_hDocument, &range, &properties); where m_hDocument is a handle

to the currently open FrameMaker file. I was wondering if anyone had a previous experience with a problem like this,

or any suggestions as to how it might be happening?

Thanks

Eric

    This topic has been closed for replies.

    1 reply

    Legend
    January 20, 2010

    Hi Eric,

    Here is a function that I use to apply a character format from the catalog, based on a preconfigured text range:

    IntT ws_ApplyCharFormatToText(F_ObjHandleT aftDocId,
                                  F_TextRangeT *aftTR,
                                  StringT aftFmtName)
    {
      F_ObjHandleT aftFmtId;

      F_PropValsT aftPropVals;

      IntT aftReturnVal = False;
     
      if(aftDocId)
      {
        //apply the format
        aftFmtId = F_ApiGetNamedObject(aftDocId, FO_CharFmt, aftFmtName);

        if(aftFmtId)
        {
          aftPropVals = F_ApiGetProps(aftDocId, aftFmtId);
          F_ApiSetTextProps(aftDocId, aftTR, &aftPropVals);
          F_ApiDeallocatePropVals(&aftPropVals);

          aftReturnVal = True;
        }
      }

      return aftReturnVal;
    }

    If you want to alter a single property (bold) to some text, my guess is that you would do something like this. I tested this and it worked. This function applies bold to whatever is currently selected:

    VoidT ws_ApplyBoldText(F_ObjHandleT docId)
    {
      F_TextRangeT tr;
      F_PropValT prop;

      IntT fontWeight;

      UIntT i;

      F_StringsT fontWeights;

      fontWeights = F_ApiGetStrings(0, FV_SessionId, FP_FontWeightNames);
      for(i = 0; i < fontWeights.len; i++)
        if(F_StrCmp(fontWeights.val, "Bold") == 0) break;

      if(i >= fontWeights.len) /* Handle error here */
      else
      {
        tr = F_ApiGetTextRange(FV_SessionId, docId, FP_TextSelection);
      
        prop = F_ApiGetTextPropVal(docId, &tr.beg, FP_FontWeight);
        prop.propVal.u.ival = i;
        F_ApiSetTextPropVal(docId, &tr, &prop);

        F_ApiDeallocatePropVal(&prop);
      }

      F_ApiDeallocateStrings(&fontWeights);

    }


    Russ

    eric247Author
    Known Participant
    January 21, 2010

    Hi Russ

    Thanks for your reply. Having looked at your code, you do broadly the same thing we do, so I think the problem lies elsewhere.

    Stepping through the debugger, I've noticed some very strange behaviour indeed, although you've probably come to expect as much

    from my posts at this stage! What is happening is, I have a sentence with a default paragraph style, and a couple of two word sections

    which are in bold like this "<paragraph format>this sentence has two bold sections starting <b> here </b> and also <b>here </b> end.</paragraph format>"

    When we are writing back the translated text we use F_ApiAddText to write it to the file, and then we use F_ApiSetTextProps to style it.

    The problem is with the word end (I can't give you the actual sentence as it is from confidential customer materials) but the sentence I've pasted is identical in structure. When we write out the equivalent to the word "end", F_ApiAddText returns an F_TextLocT with an offset of 0. My understanding was that this should contain the offset of the last character written. In this case the end offset would be in and around 70.

    This confuses our software then because we set the end offset of the range we wish to write to the offset returned by F_ApiAddText. We calculate the start offset by subtracting the length of the range's text from it's end offset so we end up with a start offset of -3!

    It gets even worse then, because these offsets seem to confuse F_ApiSetTextRange, as it ends up selecting the entire paragraph instead of the final three characters, and applying their (non-bold) formatting to it, so the bold text is being applied, but then being undone due to a text selection malfunction.

    Any ideas as to what could be causing this?

    Thanks

    Eric

    Legend
    January 21, 2010

    Hi Eric,

    I'm not having any ideas why you are getting an offset of zero. The FDK docs suggest that if the text operation fails, the return TextLoc will be invalid, but it seems that you know for sure that the text is being added. If indeed F_ApiAddText() is working, then either the FDK document is wrong or there is a bug in the FDK. And with that, you'll probably just have to make some kind of workaround. You must know the offsets where you add text and the lengths that text... couldn't you calculate the desired ranges from that?

    Russ