Skip to main content
Known Participant
October 12, 2010
Question

How to get the page number according to MarkerID?

  • October 12, 2010
  • 1 reply
  • 571 views

I want to get the page number according to the marker element in fdk. I can get the marktext and markid,How to get the page number according to MarkerID in fdk?

This topic has been closed for replies.

1 reply

Legend
October 12, 2010

zhaopeng,

You need to first get the ID of the paragraph containing the marker (with FP_TextLoc), then get the top-level frame containing the FO_Pgf object (FP_InTextFrame), then get the page containing the FO_TextFrame object (FP_PageFramePage). Here is a function that you can send various objects to in order to get the page ID, including paragraphs (this courtesy of Rick Quatro, originally posted to the Yahoo Framedev list):

F_ObjHandleT GetPage(F_ObjHandleT oDoc, F_ObjHandleT oObj)
{
  F_ObjHandleT oFrame = 0;
  IntT iObjType;
  F_ObjHandleT oRow, oCell;

  while(oObj)
  {
    oFrame = oObj;
    iObjType = F_ApiGetObjectType(oDoc, oObj);

    switch(iObjType)

    {
      case FO_SubCol:
      oObj = F_ApiGetId(oDoc, oObj, FP_ParentTextFrame);
      break;

 
      case FO_Tbl:
      oRow = F_ApiGetId(oDoc, oObj, FP_FirstRowInTbl);
      oCell = F_ApiGetId(oDoc, oRow, FP_FirstCellInRow);
      oObj = oCell;
      break;

      case FO_Row:
      oCell = F_ApiGetId(oDoc, oObj, FP_FirstCellInRow);
      oObj = oCell;
      break;


      case FO_Cell:
      case FO_Pgf:
      case FO_AFrame:
      oObj = F_ApiGetId(oDoc, oObj, FP_InTextFrame);
      break;


      case FO_TextLine:
      case FO_TextFrame:
      case FO_UnanchoredFrame:
      case FO_Arc:
      case FO_Ellipse:
      case FO_Group:
      case FO_Inset:
      case FO_Line:
      case FO_Math:
      case FO_Polygon:
      case FO_Polyline:
      case FO_Rectangle:
      case FO_RoundRect:
      oObj = F_ApiGetId(oDoc, oObj, FP_FrameParent);
      break;


      //endless loop prevention, stops the process when the top-level frame is reached

      default:

      oObj = 0;
      break;
    }
  }

  //if we found the top-level frame, return its page ID, otherwise null

  if(oFrame)

  {
    return (F_ApiGetId(oDoc, oFrame, FP_PageFramePage));
  }
  else return(0);
}

...so, you would do something like this if you have the marker ID:

F_TextLocT textLoc;

F_ObjHandleT pageId;

...

textLoc = F_ApiGetId(docId, markerId, FP_TextLoc);

pageId = GetPage(docId, pageId.objId);

Note: I'm not sure how this handles the case where a paragraph extends across two pages and the marker is located on the second page. My thought is that it might erroneously return the page where the paragraph begins. I don't know how to handle that.

Russ

zhaopengAuthor
Known Participant
October 12, 2010

thank you very much.