Skip to main content
Participating Frequently
April 14, 2010
Question

FDK - Formatting paragraphs not in Conversion table

  • April 14, 2010
  • 7 replies
  • 939 views

Hello,

I am structuring a document using a conversion table. I want to be able to apply a specific paragraph format to those paragraph format names that do not appear in the conversion table. I am having difficulty getting text from the cellIds in the Conversion table. All I get are the format names in the paragraph catalog. Maybe I am missing something here...I would appreciate any inputs.


Am pasting some code, where I've gotten so far...Questions pertaining to this issue are in the comments inline.

//Get docId, flowId, textFrameId and pgfId here...
//Open Conversion Table document here...ID is "convTabId"


F_TextRangeT ctr;
F_PropValsT props;


while(pgfId) {


//Traverse through paragraphs in the current document (docId) and get their format names.
    pgfName = F_ApiGetString(docId, pgfId, FP_Name);


    if(!pgfName) return;


    //Check if this pgfName is in the conversion table's first column..RICI, R2C1,R3C1...
    retVal = IsInConvTable(convTabId,pgfName);


    //retVal contains 1 if pgfName is in Conversion table, 0 otherwise..
    if(!retVal) {


            //Apply "Body" format to this paragraph.
            bodyFmtId = F_ApiGetNamedObject(docId,FO_PgfFmt,"Body");
            if(!bodyFmtId) return;
            props = F_ApiGetProps(docId,bodyFmtId);
            if(props.len == 0) return;


            ctr.beg.objId = ctr.end.objId = pgfId;
            ctr.beg.offset = 0;
            ctr.end.offset = FV_OBJ_END_OFFSET;
            F_ApiSetTextRange(FV_SessionId, docId, FP_TextSelection, &ctr);
            F_ApiSetProps(docId,ctr.beg.objId,&props);

      
            }
    pgfId = F_ApiGetId(docId,pgfId,FP_NextPgfInFlow);


    }
   
int IsInConvTable(F_ObjHandleT convTabId, ConStringT paraName)
{
    //declare tblId, rowId, cellId, paraId;
    F_TextItemsT textItems;
    IntT retVal=0, i;
    F_TextRangeT tr;


    //Get Table and Row Ids


    tblId = F_ApiGetId(FV_SessionId, convTabId, FP_FirstTblInDoc);
    rowId = F_ApiGetId(convTabId, tblId, FP_FirstRowInTbl);


    while(rowId) {   


        //Get Cell Ids of only the first column in each row of the Conversion table.


        cellId = F_ApiGetId(convTabId, rowId,FP_FirstCellInRow);
        paraId = F_ApiGetId(convTabId, cellId, FP_FirstPgf);
        tr.beg.objId = tr.end.objId = paraId;
        tr.beg.offset = 0;
        tr.end.offset = FV_OBJ_END_OFFSET;
        F_ApiSetTextRange(FV_SessionId, convTabId,FP_TextSelection,&tr);
        textItems = F_ApiGetTextForRange(convTabId,&tr,FTI_String);


        //Here textItems contains names in Paragraph Catalog, such as, P:Body, P:Heading1...
        //I require the entries in the conversion table and not those in the Paragraph catalog...
        //This happens if the following command is used too:
        //textItems = F_ApiGetText(convtabId,cellId,FTI_String);


        if (textItems.len != 0)
        //How do we cast textItems values to ConStringT, for the following substring operation?
             i = F_StrSubString(textItems,paraName);


        if ( != -1)
                retVal=1;


        F_ApiDeallocateTextItems(&textItems);


        rowId = F_ApiGetId(convTabId, rowId, FP_NextRowInTbl);
    }   


    return retVal;
}

Many thanks,

pnk

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Inspiring
April 23, 2010
Inspiring
April 23, 2010

Are you trying to preprocess the document before applying the conversion table? That may not be necessary. Your conversion table can use P: with no paragraph tag following the colon to refer to any paragraph format that is not explicitly named in the conversion table. Thus, there is no need to map all such paragraph formats to a catch-all format before using the conversion table.

            --Lynne

Michael_Müller-Hillebrand
Legend
April 24, 2010

Am 24.04.2010 um 01:53 schrieb Lynne Price:

Are you trying to preprocess the document before applying the conversion table? That may not be necessary. Your conversion table can use P: with no paragraph tag following the colon to refer to any paragraph format that is not explicitly named in the conversion table. Thus, there is no need to map all such paragraph formats to a catch-all format before using the conversion table.

Lynne, what a great tip! Thanks a million,

- Michael

Michael_Müller-Hillebrand
Legend
April 14, 2010

    //Get Table and Row Ids

    tblId = F_ApiGetId(FV_SessionId, convTabId, FP_FirstTblInDoc);

pnk,

to me the whole thing looks very complicated, but I guess that’s how C works and I am just a FrameScript user. I can not help you with type casting, though...

Anyway, regarding the quoted line, how can you be sure that your table is the "first table in document"? In many cases it isn’t, what you most probably want is the first table in the main flow of the document, or maybe a table with a certain table format name.

And also: You did not tell us what you really want to achieve, maybe all this can be avoided by cleverly using built-in features of the product. It seems to me you want to highlight paragraphs which will not be handled by a conversion table (for going to structured?). If this is the case, assigning another paragraph format will remove any information of the paragraph.

- Michael

pnk80Author
Participating Frequently
April 14, 2010

Hi Michael,

Thanks for your reply. I should have given an overview of what I am trying to achieve.

I have an unstructured document, with numerous paragraphs, each having different formats. I want to convert this document to a structured one. However, I do not want to define all the paragraph format names(most of them not-so-relevant) in my Conversion table. So I only define the most important paragraph format names in the Conversion table.

The idea is to format all the other (not-so-relevant) different paragraph format names, with a single pgf format name, say for example, "Body" - so that I can define only P:Body in my conversion table and wrap it up in an element. Perhaps there are other methods, this was just an idea..

In the code, first I open the document containing the conversion table. This document contains only one table - i.e, the conversion table. Thats the reason for using FP_FirstTblInDoc property.

    //Get Table and Row Ids

     tblId = F_ApiGetId(FV_SessionId, convTabId, FP_FirstTblInDoc);

The algorithm goes like:

  1. Traverse all paragraphs in the unstructured document
  2. Get each paragraph's format name (FP_Name) property.
  3. For each FP_Name obtained, parse the conversion table's first column - R1C1, R2C1, R3C1, R4C1 etc...and look if the FP_Name value is defined in any of these cells. This is achieved by getting the text out of each cell and comparing it with FP_Name value. (This is where I am stumped).
  4. If there is no match, then the paragraph is not-so-relevant, so give the paragraph in the unstructured document a different format name, say "Body".

Hope this helps..


I found a solution for casting "textItems", though I don't know if its the correct way.

declare a char array;

char *dbmsg;

for(k=0;k<textItems.len;k++){
      F_Sprintf(dbmsg,textItems.val.u.sdata);
}

Now, dbmsg holds the value in the textItems. This can be used in the F_SubStr function.

Many thanks,

pnk