Home | History | Annotate | Download | only in parser
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "xfa/src/foxitlib.h"
      8 #include "xfa/src/fxfa/src/common/xfa_utils.h"
      9 #include "xfa/src/fxfa/src/common/xfa_object.h"
     10 #include "xfa/src/fxfa/src/common/xfa_document.h"
     11 #include "xfa/src/fxfa/src/common/xfa_parser.h"
     12 #include "xfa/src/fxfa/src/common/xfa_script.h"
     13 #include "xfa/src/fxfa/src/common/xfa_docdata.h"
     14 #include "xfa/src/fxfa/src/common/xfa_doclayout.h"
     15 #include "xfa/src/fxfa/src/common/xfa_localemgr.h"
     16 #include "xfa/src/fxfa/src/common/xfa_fm2jsapi.h"
     17 #include "xfa_script_layoutpseudomodel.h"
     18 #include "xfa_document_layout_imp.h"
     19 #include "xfa_layout_appadapter.h"
     20 CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument)
     21     : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_LayoutPseudoModel) {
     22   m_uScriptHash = XFA_HASHCODE_Layout;
     23 }
     24 CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {}
     25 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Ready(
     26     FXJSE_HVALUE hValue,
     27     FX_BOOL bSetting,
     28     XFA_ATTRIBUTE eAttribute) {
     29   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
     30   if (!pNotify) {
     31     return;
     32   }
     33   if (bSetting) {
     34     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_READY);
     35     return;
     36   }
     37   int32_t iStatus = pNotify->GetLayoutStatus();
     38   FXJSE_Value_SetBoolean(hValue, iStatus >= 2);
     39 }
     40 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_HWXY(
     41     CFXJSE_Arguments* pArguments,
     42     XFA_LAYOUTMODEL_HWXY layoutModel) {
     43   int32_t iLength = pArguments->GetLength();
     44   if (iLength < 1 || iLength > 3) {
     45     const FX_WCHAR* methodName = NULL;
     46     switch (layoutModel) {
     47       case XFA_LAYOUTMODEL_H:
     48         methodName = L"h";
     49         break;
     50       case XFA_LAYOUTMODEL_W:
     51         methodName = L"w";
     52         break;
     53       case XFA_LAYOUTMODEL_X:
     54         methodName = L"x";
     55         break;
     56       case XFA_LAYOUTMODEL_Y:
     57         methodName = L"y";
     58         break;
     59     }
     60     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);
     61     return;
     62   }
     63   CXFA_Node* pNode = NULL;
     64   CFX_WideString wsUnit = FX_WSTRC(L"pt");
     65   int32_t iIndex = 0;
     66   if (iLength >= 1) {
     67     pNode = (CXFA_Node*)pArguments->GetObject(0);
     68   }
     69   if (iLength >= 2) {
     70     CFX_ByteString bsUnit = pArguments->GetUTF8String(1);
     71     if (!bsUnit.IsEmpty()) {
     72       wsUnit = CFX_WideString::FromUTF8(bsUnit, bsUnit.GetLength());
     73     }
     74   }
     75   if (iLength >= 3) {
     76     iIndex = pArguments->GetInt32(2);
     77   }
     78   if (!pNode) {
     79     return;
     80   }
     81   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
     82   if (!pDocLayout) {
     83     return;
     84   }
     85   CFX_RectF rtRect;
     86   CXFA_Measurement measure;
     87   CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
     88   if (!pLayoutItem) {
     89     return;
     90   }
     91   while (iIndex > 0 && pLayoutItem) {
     92     pLayoutItem = pLayoutItem->GetNext();
     93     iIndex--;
     94   }
     95   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
     96   if (!pLayoutItem) {
     97     FXJSE_Value_SetFloat(hValue, 0);
     98     return;
     99   }
    100   pLayoutItem->GetRect(rtRect, TRUE);
    101   switch (layoutModel) {
    102     case XFA_LAYOUTMODEL_H:
    103       measure.Set(rtRect.height, XFA_UNIT_Pt);
    104       break;
    105     case XFA_LAYOUTMODEL_W:
    106       measure.Set(rtRect.width, XFA_UNIT_Pt);
    107       break;
    108     case XFA_LAYOUTMODEL_X:
    109       measure.Set(rtRect.left, XFA_UNIT_Pt);
    110       break;
    111     case XFA_LAYOUTMODEL_Y:
    112       measure.Set(rtRect.top, XFA_UNIT_Pt);
    113       break;
    114   }
    115   XFA_UNIT unit = measure.GetUnit(wsUnit);
    116   FX_FLOAT fValue = measure.ToUnit(unit);
    117   fValue = FXSYS_round(fValue * 1000) / 1000.0f;
    118   if (hValue) {
    119     FXJSE_Value_SetFloat(hValue, fValue);
    120   }
    121 }
    122 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_H(
    123     CFXJSE_Arguments* pArguments) {
    124   Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_H);
    125 }
    126 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_W(
    127     CFXJSE_Arguments* pArguments) {
    128   Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_W);
    129 }
    130 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_X(
    131     CFXJSE_Arguments* pArguments) {
    132   Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_X);
    133 }
    134 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Y(
    135     CFXJSE_Arguments* pArguments) {
    136   Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_Y);
    137 }
    138 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_NumberedPageCount(
    139     CFXJSE_Arguments* pArguments,
    140     FX_BOOL bNumbered) {
    141   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    142   if (!pDocLayout) {
    143     return;
    144   }
    145   int32_t iPageCount = 0;
    146   int32_t iPageNum = pDocLayout->CountPages();
    147   if (bNumbered) {
    148     for (int32_t i = 0; i < iPageNum; i++) {
    149       IXFA_LayoutPage* pLayoutPage = pDocLayout->GetPage(i);
    150       if (!pLayoutPage) {
    151         continue;
    152       }
    153       CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage();
    154       if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) {
    155         iPageCount++;
    156       }
    157     }
    158   } else {
    159     iPageCount = iPageNum;
    160   }
    161   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    162   if (hValue) {
    163     FXJSE_Value_SetInteger(hValue, iPageCount);
    164   }
    165 }
    166 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageCount(
    167     CFXJSE_Arguments* pArguments) {
    168   Script_LayoutPseudoModel_NumberedPageCount(pArguments, TRUE);
    169 }
    170 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageSpan(
    171     CFXJSE_Arguments* pArguments) {
    172   int32_t iLength = pArguments->GetLength();
    173   if (iLength != 1) {
    174     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan");
    175     return;
    176   }
    177   CXFA_Node* pNode = NULL;
    178   if (iLength >= 1) {
    179     pNode = (CXFA_Node*)pArguments->GetObject(0);
    180   }
    181   if (!pNode) {
    182     return;
    183   }
    184   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    185   if (!pDocLayout) {
    186     return;
    187   }
    188   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    189   CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
    190   if (!pLayoutItem) {
    191     FXJSE_Value_SetInteger(hValue, -1);
    192     return;
    193   }
    194   int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex();
    195   int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
    196   int32_t iPageSpan = iLast - iFirst + 1;
    197   if (hValue) {
    198     FXJSE_Value_SetInteger(hValue, iPageSpan);
    199   }
    200 }
    201 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Page(
    202     CFXJSE_Arguments* pArguments) {
    203   Script_LayoutPseudoModel_PageImp(pArguments, FALSE);
    204 }
    205 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_GetObjArray(
    206     IXFA_DocLayout* pDocLayout,
    207     int32_t iPageNo,
    208     const CFX_WideString& wsType,
    209     FX_BOOL bOnPageArea,
    210     CXFA_NodeArray& retArray) {
    211   CXFA_ContainerLayoutItem* pLayoutPage =
    212       (CXFA_ContainerLayoutItem*)pDocLayout->GetPage(iPageNo);
    213   if (!pLayoutPage) {
    214     return;
    215   }
    216   if (wsType == FX_WSTRC(L"pageArea")) {
    217     if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) {
    218       retArray.Add(pMasterPage);
    219     }
    220     return;
    221   }
    222   if (wsType == FX_WSTRC(L"contentArea")) {
    223     for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
    224          pItem = pItem->m_pNextSibling) {
    225       if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
    226         retArray.Add(pItem->m_pFormNode);
    227       }
    228     }
    229     return;
    230   }
    231   CFX_MapPtrToPtr formItems;
    232   formItems.InitHashTable(256, TRUE);
    233   if (wsType.IsEmpty()) {
    234     if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) {
    235       retArray.Add(pMasterPage);
    236     }
    237     for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
    238          pItem = pItem->m_pNextSibling) {
    239       if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
    240         retArray.Add(pItem->m_pFormNode);
    241         if (!bOnPageArea) {
    242           CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
    243                                     CXFA_TraverseStrategy_ContentLayoutItem>
    244           iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild);
    245           for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
    246                pItemChild; pItemChild = iterator.MoveToNext()) {
    247             if (!pItemChild->IsContentLayoutItem()) {
    248               continue;
    249             }
    250             XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();
    251             if (eElementType != XFA_ELEMENT_Field &&
    252                 eElementType != XFA_ELEMENT_Draw &&
    253                 eElementType != XFA_ELEMENT_Subform &&
    254                 eElementType != XFA_ELEMENT_Area) {
    255               continue;
    256             }
    257             if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
    258               continue;
    259             }
    260             formItems.SetAt(pItemChild->m_pFormNode, this);
    261             retArray.Add(pItemChild->m_pFormNode);
    262           }
    263         }
    264       } else {
    265         if (bOnPageArea) {
    266           CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
    267                                     CXFA_TraverseStrategy_ContentLayoutItem>
    268           iterator((CXFA_ContentLayoutItem*)pItem);
    269           for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
    270                pItemChild; pItemChild = iterator.MoveToNext()) {
    271             if (!pItemChild->IsContentLayoutItem()) {
    272               continue;
    273             }
    274             XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();
    275             if (eElementType != XFA_ELEMENT_Field &&
    276                 eElementType != XFA_ELEMENT_Draw &&
    277                 eElementType != XFA_ELEMENT_Subform &&
    278                 eElementType != XFA_ELEMENT_Area) {
    279               continue;
    280             }
    281             if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
    282               continue;
    283             }
    284             formItems.SetAt(pItemChild->m_pFormNode, this);
    285             retArray.Add(pItemChild->m_pFormNode);
    286           }
    287         }
    288       }
    289     }
    290     return;
    291   }
    292   XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN;
    293   if (wsType == FX_WSTRC(L"field")) {
    294     eType = XFA_ELEMENT_Field;
    295   } else if (wsType == FX_WSTRC(L"draw")) {
    296     eType = XFA_ELEMENT_Draw;
    297   } else if (wsType == FX_WSTRC(L"subform")) {
    298     eType = XFA_ELEMENT_Subform;
    299   } else if (wsType == FX_WSTRC(L"area")) {
    300     eType = XFA_ELEMENT_Area;
    301   }
    302   if (eType != XFA_ELEMENT_UNKNOWN) {
    303     for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
    304          pItem = pItem->m_pNextSibling) {
    305       if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
    306         if (!bOnPageArea) {
    307           CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
    308                                     CXFA_TraverseStrategy_ContentLayoutItem>
    309           iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild);
    310           for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
    311                pItemChild; pItemChild = iterator.MoveToNext()) {
    312             if (!pItemChild->IsContentLayoutItem()) {
    313               continue;
    314             }
    315             if (pItemChild->m_pFormNode->GetClassID() != eType) {
    316               continue;
    317             }
    318             if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
    319               continue;
    320             }
    321             formItems.SetAt(pItemChild->m_pFormNode, this);
    322             retArray.Add(pItemChild->m_pFormNode);
    323           }
    324         }
    325       } else {
    326         if (bOnPageArea) {
    327           CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
    328                                     CXFA_TraverseStrategy_ContentLayoutItem>
    329           iterator((CXFA_ContentLayoutItem*)pItem);
    330           for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
    331                pItemChild; pItemChild = iterator.MoveToNext()) {
    332             if (!pItemChild->IsContentLayoutItem()) {
    333               continue;
    334             }
    335             if (pItemChild->m_pFormNode->GetClassID() != eType) {
    336               continue;
    337             }
    338             if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
    339               continue;
    340             }
    341             formItems.SetAt(pItemChild->m_pFormNode, this);
    342             retArray.Add(pItemChild->m_pFormNode);
    343           }
    344         }
    345       }
    346     }
    347     return;
    348   }
    349 }
    350 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageContent(
    351     CFXJSE_Arguments* pArguments) {
    352   int32_t iLength = pArguments->GetLength();
    353   if (iLength < 1 || iLength > 3) {
    354     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent");
    355     return;
    356   }
    357   int32_t iIndex = 0;
    358   CFX_WideString wsType;
    359   FX_BOOL bOnPageArea = FALSE;
    360   if (iLength >= 1) {
    361     iIndex = pArguments->GetInt32(0);
    362   }
    363   if (iLength >= 2) {
    364     CFX_ByteString bsType = pArguments->GetUTF8String(1);
    365     wsType = CFX_WideString::FromUTF8(bsType, bsType.GetLength());
    366   }
    367   if (iLength >= 3) {
    368     bOnPageArea = pArguments->GetInt32(2) == 0 ? FALSE : TRUE;
    369   }
    370   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    371   if (!pNotify) {
    372     return;
    373   }
    374   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    375   if (!pDocLayout) {
    376     return;
    377   }
    378   CXFA_NodeArray retArray;
    379   Script_LayoutPseudoModel_GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea,
    380                                        retArray);
    381   CXFA_ArrayNodeList* pArrayNodeList = new CXFA_ArrayNodeList(m_pDocument);
    382   pArrayNodeList->SetArrayNodeList(retArray);
    383   FXJSE_Value_SetObject(pArguments->GetReturnValue(),
    384                         (CXFA_Object*)pArrayNodeList,
    385                         m_pDocument->GetScriptContext()->GetJseNormalClass());
    386 }
    387 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageCount(
    388     CFXJSE_Arguments* pArguments) {
    389   Script_LayoutPseudoModel_NumberedPageCount(pArguments, FALSE);
    390 }
    391 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageCountInBatch(
    392     CFXJSE_Arguments* pArguments) {
    393   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    394   if (!pNotify) {
    395     return;
    396   }
    397   IXFA_Doc* hDoc = pNotify->GetHDOC();
    398   int32_t iPageCount = pNotify->GetDocProvider()->AbsPageCountInBatch(hDoc);
    399   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    400   if (hValue) {
    401     FXJSE_Value_SetInteger(hValue, iPageCount);
    402   }
    403 }
    404 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetCountInBatch(
    405     CFXJSE_Arguments* pArguments) {
    406   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    407   if (!pNotify) {
    408     return;
    409   }
    410   IXFA_Doc* hDoc = pNotify->GetHDOC();
    411   int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc);
    412   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    413   if (hValue) {
    414     FXJSE_Value_SetInteger(hValue, iPageCount);
    415   }
    416 }
    417 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Relayout(
    418     CFXJSE_Arguments* pArguments) {
    419   CXFA_Node* pRootNode = m_pDocument->GetRoot();
    420   CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_ELEMENT_Form);
    421   FXSYS_assert(pFormRoot);
    422   CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
    423   CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor();
    424   if (pContentRootNode) {
    425     pLayoutProcessor->AddChangedContainer(pContentRootNode);
    426   }
    427   pLayoutProcessor->SetForceReLayout(TRUE);
    428 }
    429 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageSpan(
    430     CFXJSE_Arguments* pArguments) {
    431   Script_LayoutPseudoModel_PageSpan(pArguments);
    432 }
    433 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageInBatch(
    434     CFXJSE_Arguments* pArguments) {
    435   int32_t iLength = pArguments->GetLength();
    436   if (iLength != 1) {
    437     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
    438                             L"absPageInBatch");
    439     return;
    440   }
    441   CXFA_Node* pNode = NULL;
    442   if (iLength >= 1) {
    443     pNode = (CXFA_Node*)pArguments->GetObject(0);
    444   }
    445   if (!pNode) {
    446     return;
    447   }
    448   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    449   if (!pNotify) {
    450     return;
    451   }
    452   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    453   if (!pDocLayout) {
    454     return;
    455   }
    456   IXFA_Widget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
    457   if (!hWidget) {
    458     return;
    459   }
    460   IXFA_Doc* hDoc = pNotify->GetHDOC();
    461   int32_t iPageCount = pNotify->GetDocProvider()->AbsPageInBatch(hDoc, hWidget);
    462   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    463   if (hValue) {
    464     FXJSE_Value_SetInteger(hValue, iPageCount);
    465   }
    466 }
    467 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetInBatch(
    468     CFXJSE_Arguments* pArguments) {
    469   int32_t iLength = pArguments->GetLength();
    470   if (iLength != 1) {
    471     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
    472                             L"sheetInBatch");
    473     return;
    474   }
    475   CXFA_Node* pNode = NULL;
    476   if (iLength >= 1) {
    477     pNode = (CXFA_Node*)pArguments->GetObject(0);
    478   }
    479   if (!pNode) {
    480     return;
    481   }
    482   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    483   if (!pNotify) {
    484     return;
    485   }
    486   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    487   if (!pDocLayout) {
    488     return;
    489   }
    490   IXFA_Widget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
    491   if (!hWidget) {
    492     return;
    493   }
    494   IXFA_Doc* hDoc = pNotify->GetHDOC();
    495   int32_t iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget);
    496   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    497   if (hValue) {
    498     FXJSE_Value_SetInteger(hValue, iPageCount);
    499   }
    500 }
    501 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Sheet(
    502     CFXJSE_Arguments* pArguments) {
    503   Script_LayoutPseudoModel_PageImp(pArguments, TRUE);
    504 }
    505 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_RelayoutPageArea(
    506     CFXJSE_Arguments* pArguments) {}
    507 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetCount(
    508     CFXJSE_Arguments* pArguments) {
    509   Script_LayoutPseudoModel_NumberedPageCount(pArguments, FALSE);
    510 }
    511 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPage(
    512     CFXJSE_Arguments* pArguments) {
    513   Script_LayoutPseudoModel_PageImp(pArguments, TRUE);
    514 }
    515 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageImp(
    516     CFXJSE_Arguments* pArguments,
    517     FX_BOOL bAbsPage) {
    518   int32_t iLength = pArguments->GetLength();
    519   if (iLength != 1) {
    520     const FX_WCHAR* methodName;
    521     if (bAbsPage) {
    522       methodName = L"absPage";
    523     } else {
    524       methodName = L"page";
    525     }
    526     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);
    527     return;
    528   }
    529   CXFA_Node* pNode = NULL;
    530   if (iLength >= 1) {
    531     pNode = (CXFA_Node*)pArguments->GetObject(0);
    532   }
    533   int32_t iPage = 0;
    534   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    535   if (!pNode && hValue) {
    536     FXJSE_Value_SetInteger(hValue, iPage);
    537   }
    538   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    539   if (!pDocLayout) {
    540     return;
    541   }
    542   CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
    543   if (!pLayoutItem) {
    544     FXJSE_Value_SetInteger(hValue, -1);
    545     return;
    546   }
    547   iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
    548   if (hValue) {
    549     FXJSE_Value_SetInteger(hValue, bAbsPage ? iPage : iPage + 1);
    550   }
    551 }
    552