| OLD | NEW |
| (Empty) |
| 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/fxfa/parser/xfa_basic_imp.h" | |
| 8 | |
| 9 #include "core/include/fxcrt/fx_ext.h" | |
| 10 #include "xfa/src/fgas/crt/fgas_algorithm.h" | |
| 11 #include "xfa/src/fgas/crt/fgas_codepage.h" | |
| 12 #include "xfa/src/fgas/crt/fgas_system.h" | |
| 13 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h" | |
| 14 #include "xfa/src/fxfa/parser/xfa_basic_data.h" | |
| 15 #include "xfa/src/fxfa/parser/xfa_docdata.h" | |
| 16 #include "xfa/src/fxfa/parser/xfa_doclayout.h" | |
| 17 #include "xfa/src/fxfa/parser/xfa_document.h" | |
| 18 #include "xfa/src/fxfa/parser/xfa_localemgr.h" | |
| 19 #include "xfa/src/fxfa/parser/xfa_object.h" | |
| 20 #include "xfa/src/fxfa/parser/xfa_parser.h" | |
| 21 #include "xfa/src/fxfa/parser/xfa_script.h" | |
| 22 #include "xfa/src/fxfa/parser/xfa_utils.h" | |
| 23 | |
| 24 const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { | |
| 25 int32_t iLength = wsName.GetLength(); | |
| 26 if (iLength == 0) { | |
| 27 return NULL; | |
| 28 } | |
| 29 uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength); | |
| 30 int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; | |
| 31 do { | |
| 32 int32_t iMid = (iStart + iEnd) / 2; | |
| 33 const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; | |
| 34 if (uHash == pInfo->uHash) { | |
| 35 return pInfo; | |
| 36 } else if (uHash < pInfo->uHash) { | |
| 37 iEnd = iMid - 1; | |
| 38 } else { | |
| 39 iStart = iMid + 1; | |
| 40 } | |
| 41 } while (iStart <= iEnd); | |
| 42 return NULL; | |
| 43 } | |
| 44 | |
| 45 const XFA_PACKETINFO* XFA_GetPacketByID(FX_DWORD dwPacket) { | |
| 46 int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; | |
| 47 do { | |
| 48 int32_t iMid = (iStart + iEnd) / 2; | |
| 49 FX_DWORD dwFind = (g_XFAPacketData + iMid)->eName; | |
| 50 if (dwPacket == dwFind) { | |
| 51 return g_XFAPacketData + iMid; | |
| 52 } else if (dwPacket < dwFind) { | |
| 53 iEnd = iMid - 1; | |
| 54 } else { | |
| 55 iStart = iMid + 1; | |
| 56 } | |
| 57 } while (iStart <= iEnd); | |
| 58 return NULL; | |
| 59 } | |
| 60 | |
| 61 const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { | |
| 62 return g_XFAPacketData + ePacket; | |
| 63 } | |
| 64 | |
| 65 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( | |
| 66 const CFX_WideStringC& wsName) { | |
| 67 int32_t iLength = wsName.GetLength(); | |
| 68 if (iLength == 0) { | |
| 69 return NULL; | |
| 70 } | |
| 71 uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength); | |
| 72 int32_t iStart = 0, iEnd = g_iXFAEnumCount - 1; | |
| 73 do { | |
| 74 int32_t iMid = (iStart + iEnd) / 2; | |
| 75 const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid; | |
| 76 if (uHash == pInfo->uHash) { | |
| 77 return pInfo; | |
| 78 } else if (uHash < pInfo->uHash) { | |
| 79 iEnd = iMid - 1; | |
| 80 } else { | |
| 81 iStart = iMid + 1; | |
| 82 } | |
| 83 } while (iStart <= iEnd); | |
| 84 return NULL; | |
| 85 } | |
| 86 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { | |
| 87 return g_XFAEnumData + eName; | |
| 88 } | |
| 89 int32_t XFA_GetAttributeCount() { | |
| 90 return g_iXFAAttributeCount; | |
| 91 } | |
| 92 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { | |
| 93 int32_t iLength = wsName.GetLength(); | |
| 94 if (iLength == 0) { | |
| 95 return NULL; | |
| 96 } | |
| 97 uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength); | |
| 98 int32_t iStart = 0, iEnd = g_iXFAAttributeCount - 1; | |
| 99 do { | |
| 100 int32_t iMid = (iStart + iEnd) / 2; | |
| 101 const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; | |
| 102 if (uHash == pInfo->uHash) { | |
| 103 return pInfo; | |
| 104 } else if (uHash < pInfo->uHash) { | |
| 105 iEnd = iMid - 1; | |
| 106 } else { | |
| 107 iStart = iMid + 1; | |
| 108 } | |
| 109 } while (iStart <= iEnd); | |
| 110 return NULL; | |
| 111 } | |
| 112 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { | |
| 113 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; | |
| 114 } | |
| 115 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, | |
| 116 XFA_ELEMENT eElement, | |
| 117 XFA_ATTRIBUTE eAttribute, | |
| 118 XFA_ATTRIBUTETYPE eType, | |
| 119 FX_DWORD dwPacket) { | |
| 120 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | |
| 121 if (pInfo == NULL) { | |
| 122 return FALSE; | |
| 123 } | |
| 124 if (dwPacket && (dwPacket & pInfo->dwPackets) == 0) { | |
| 125 return FALSE; | |
| 126 } | |
| 127 if (pInfo->eType == eType) { | |
| 128 pValue = pInfo->pDefValue; | |
| 129 return TRUE; | |
| 130 } else if (pInfo->eType == XFA_ATTRIBUTETYPE_NOTSURE) { | |
| 131 const XFA_NOTSUREATTRIBUTE* pAttr = | |
| 132 XFA_GetNotsureAttribute(eElement, eAttribute, eType); | |
| 133 if (pAttr) { | |
| 134 pValue = pAttr->pValue; | |
| 135 return TRUE; | |
| 136 } | |
| 137 } | |
| 138 return FALSE; | |
| 139 } | |
| 140 XFA_ATTRIBUTEENUM XFA_GetAttributeDefaultValue_Enum(XFA_ELEMENT eElement, | |
| 141 XFA_ATTRIBUTE eAttribute, | |
| 142 FX_DWORD dwPacket) { | |
| 143 void* pValue; | |
| 144 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 145 XFA_ATTRIBUTETYPE_Enum, dwPacket)) { | |
| 146 return (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; | |
| 147 } | |
| 148 return XFA_ATTRIBUTEENUM_Unknown; | |
| 149 } | |
| 150 CFX_WideStringC XFA_GetAttributeDefaultValue_Cdata(XFA_ELEMENT eElement, | |
| 151 XFA_ATTRIBUTE eAttribute, | |
| 152 FX_DWORD dwPacket) { | |
| 153 void* pValue; | |
| 154 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 155 XFA_ATTRIBUTETYPE_Cdata, dwPacket)) { | |
| 156 return (const FX_WCHAR*)pValue; | |
| 157 } | |
| 158 return NULL; | |
| 159 } | |
| 160 FX_BOOL XFA_GetAttributeDefaultValue_Boolean(XFA_ELEMENT eElement, | |
| 161 XFA_ATTRIBUTE eAttribute, | |
| 162 FX_DWORD dwPacket) { | |
| 163 void* pValue; | |
| 164 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 165 XFA_ATTRIBUTETYPE_Boolean, dwPacket)) { | |
| 166 return (FX_BOOL)(uintptr_t)pValue; | |
| 167 } | |
| 168 return FALSE; | |
| 169 } | |
| 170 int32_t XFA_GetAttributeDefaultValue_Integer(XFA_ELEMENT eElement, | |
| 171 XFA_ATTRIBUTE eAttribute, | |
| 172 FX_DWORD dwPacket) { | |
| 173 void* pValue; | |
| 174 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 175 XFA_ATTRIBUTETYPE_Integer, dwPacket)) { | |
| 176 return (int32_t)(uintptr_t)pValue; | |
| 177 } | |
| 178 return 0; | |
| 179 } | |
| 180 CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_ELEMENT eElement, | |
| 181 XFA_ATTRIBUTE eAttribute, | |
| 182 FX_DWORD dwPacket) { | |
| 183 void* pValue; | |
| 184 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 185 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { | |
| 186 return *(CXFA_Measurement*)pValue; | |
| 187 } | |
| 188 return CXFA_Measurement(); | |
| 189 } | |
| 190 int32_t XFA_GetElementCount() { | |
| 191 return g_iXFAElementCount; | |
| 192 } | |
| 193 const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { | |
| 194 int32_t iLength = wsName.GetLength(); | |
| 195 if (iLength == 0) { | |
| 196 return NULL; | |
| 197 } | |
| 198 uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength); | |
| 199 int32_t iStart = 0, iEnd = g_iXFAElementCount - 1; | |
| 200 do { | |
| 201 int32_t iMid = (iStart + iEnd) / 2; | |
| 202 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; | |
| 203 if (uHash == pInfo->uHash) { | |
| 204 return pInfo; | |
| 205 } else if (uHash < pInfo->uHash) { | |
| 206 iEnd = iMid - 1; | |
| 207 } else { | |
| 208 iStart = iMid + 1; | |
| 209 } | |
| 210 } while (iStart <= iEnd); | |
| 211 return NULL; | |
| 212 } | |
| 213 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_ELEMENT eName) { | |
| 214 return (eName < g_iXFAElementCount) ? (g_XFAElementData + eName) : NULL; | |
| 215 } | |
| 216 const FX_WORD* XFA_GetElementChildren(XFA_ELEMENT eElement, int32_t& iCount) { | |
| 217 if (eElement >= g_iXFAElementCount) { | |
| 218 return NULL; | |
| 219 } | |
| 220 const XFA_ELEMENTHIERARCHY* pElement = g_XFAElementChildrenIndex + eElement; | |
| 221 iCount = pElement->wCount; | |
| 222 return g_XFAElementChildrenData + pElement->wStart; | |
| 223 } | |
| 224 const uint8_t* XFA_GetElementAttributes(XFA_ELEMENT eElement, int32_t& iCount) { | |
| 225 if (eElement >= g_iXFAElementCount) { | |
| 226 return NULL; | |
| 227 } | |
| 228 const XFA_ELEMENTHIERARCHY* pElement = g_XFAElementAttributeIndex + eElement; | |
| 229 iCount = pElement->wCount; | |
| 230 return g_XFAElementAttributeData + pElement->wStart; | |
| 231 } | |
| 232 const XFA_ATTRIBUTEINFO* XFA_GetAttributeOfElement(XFA_ELEMENT eElement, | |
| 233 XFA_ATTRIBUTE eAttribute, | |
| 234 FX_DWORD dwPacket) { | |
| 235 int32_t iCount = 0; | |
| 236 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); | |
| 237 if (pAttr == NULL || iCount < 1) { | |
| 238 return NULL; | |
| 239 } | |
| 240 CFX_DSPATemplate<uint8_t> search; | |
| 241 int32_t index = search.Lookup(eAttribute, pAttr, iCount); | |
| 242 if (index < 0) { | |
| 243 return NULL; | |
| 244 } | |
| 245 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | |
| 246 ASSERT(pInfo); | |
| 247 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | |
| 248 return pInfo; | |
| 249 return (dwPacket & pInfo->dwPackets) ? pInfo : NULL; | |
| 250 } | |
| 251 const XFA_ELEMENTINFO* XFA_GetChildOfElement(XFA_ELEMENT eElement, | |
| 252 XFA_ELEMENT eChild, | |
| 253 FX_DWORD dwPacket) { | |
| 254 int32_t iCount = 0; | |
| 255 const FX_WORD* pChild = XFA_GetElementChildren(eElement, iCount); | |
| 256 if (pChild == NULL || iCount < 1) { | |
| 257 return NULL; | |
| 258 } | |
| 259 CFX_DSPATemplate<FX_WORD> search; | |
| 260 int32_t index = search.Lookup(eChild, pChild, iCount); | |
| 261 if (index < 0) { | |
| 262 return NULL; | |
| 263 } | |
| 264 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eChild); | |
| 265 ASSERT(pInfo); | |
| 266 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | |
| 267 return pInfo; | |
| 268 return (dwPacket & pInfo->dwPackets) ? pInfo : NULL; | |
| 269 } | |
| 270 const XFA_PROPERTY* XFA_GetElementProperties(XFA_ELEMENT eElement, | |
| 271 int32_t& iCount) { | |
| 272 if (eElement >= g_iXFAElementCount) { | |
| 273 return NULL; | |
| 274 } | |
| 275 const XFA_ELEMENTHIERARCHY* pElement = g_XFAElementPropertyIndex + eElement; | |
| 276 iCount = pElement->wCount; | |
| 277 return g_XFAElementPropertyData + pElement->wStart; | |
| 278 } | |
| 279 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_ELEMENT eElement, | |
| 280 XFA_ELEMENT eProperty, | |
| 281 FX_DWORD dwPacket) { | |
| 282 int32_t iCount = 0; | |
| 283 const XFA_PROPERTY* pProperty = XFA_GetElementProperties(eElement, iCount); | |
| 284 if (pProperty == NULL || iCount < 1) { | |
| 285 return NULL; | |
| 286 } | |
| 287 int32_t iStart = 0, iEnd = iCount - 1, iMid; | |
| 288 do { | |
| 289 iMid = (iStart + iEnd) / 2; | |
| 290 XFA_ELEMENT eName = (XFA_ELEMENT)pProperty[iMid].eName; | |
| 291 if (eProperty == eName) { | |
| 292 break; | |
| 293 } else if (eProperty < eName) { | |
| 294 iEnd = iMid - 1; | |
| 295 } else { | |
| 296 iStart = iMid + 1; | |
| 297 } | |
| 298 } while (iStart <= iEnd); | |
| 299 if (iStart > iEnd) { | |
| 300 return NULL; | |
| 301 } | |
| 302 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); | |
| 303 ASSERT(pInfo); | |
| 304 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | |
| 305 return pProperty + iMid; | |
| 306 return (dwPacket & pInfo->dwPackets) ? (pProperty + iMid) : NULL; | |
| 307 } | |
| 308 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_ELEMENT eElement, | |
| 309 XFA_ATTRIBUTE eAttribute, | |
| 310 XFA_ATTRIBUTETYPE eType) { | |
| 311 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; | |
| 312 do { | |
| 313 int32_t iMid = (iStart + iEnd) / 2; | |
| 314 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; | |
| 315 if (eElement == pAttr->eElement) { | |
| 316 if (pAttr->eAttribute == eAttribute) { | |
| 317 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { | |
| 318 return pAttr; | |
| 319 } | |
| 320 return NULL; | |
| 321 } else { | |
| 322 int32_t iBefore = iMid - 1; | |
| 323 if (iBefore >= 0) { | |
| 324 pAttr = g_XFANotsureAttributes + iBefore; | |
| 325 while (eElement == pAttr->eElement) { | |
| 326 if (pAttr->eAttribute == eAttribute) { | |
| 327 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { | |
| 328 return pAttr; | |
| 329 } | |
| 330 return NULL; | |
| 331 } | |
| 332 iBefore--; | |
| 333 if (iBefore < 0) { | |
| 334 break; | |
| 335 } | |
| 336 pAttr = g_XFANotsureAttributes + iBefore; | |
| 337 } | |
| 338 } | |
| 339 int32_t iAfter = iMid + 1; | |
| 340 if (iAfter <= g_iXFANotsureCount - 1) { | |
| 341 pAttr = g_XFANotsureAttributes + iAfter; | |
| 342 while (eElement == pAttr->eElement) { | |
| 343 if (pAttr->eAttribute == eAttribute) { | |
| 344 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { | |
| 345 return pAttr; | |
| 346 } | |
| 347 return NULL; | |
| 348 } | |
| 349 iAfter++; | |
| 350 if (iAfter > g_iXFANotsureCount - 1) { | |
| 351 break; | |
| 352 } | |
| 353 pAttr = g_XFANotsureAttributes + iAfter; | |
| 354 } | |
| 355 } | |
| 356 return NULL; | |
| 357 } | |
| 358 } else if (eElement < pAttr->eElement) { | |
| 359 iEnd = iMid - 1; | |
| 360 } else { | |
| 361 iStart = iMid + 1; | |
| 362 } | |
| 363 } while (iStart <= iEnd); | |
| 364 return NULL; | |
| 365 } | |
| 366 int32_t XFA_GetMethodCount() { | |
| 367 return g_iSomMethodCount; | |
| 368 } | |
| 369 const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, | |
| 370 const CFX_WideStringC& wsMethodName) { | |
| 371 int32_t iLength = wsMethodName.GetLength(); | |
| 372 if (iLength == 0) { | |
| 373 return NULL; | |
| 374 } | |
| 375 int32_t iElementIndex = eElement; | |
| 376 while (iElementIndex != -1) { | |
| 377 XFA_LPCSCRIPTHIERARCHY scriptIndex = g_XFAScriptIndex + iElementIndex; | |
| 378 int32_t icount = scriptIndex->wMethodCount; | |
| 379 if (icount == 0) { | |
| 380 iElementIndex = scriptIndex->wParentIndex; | |
| 381 continue; | |
| 382 } | |
| 383 uint32_t uHash = FX_HashCode_String_GetW(wsMethodName.GetPtr(), iLength); | |
| 384 int32_t iStart = scriptIndex->wMethodStart, iEnd = iStart + icount - 1; | |
| 385 do { | |
| 386 int32_t iMid = (iStart + iEnd) / 2; | |
| 387 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; | |
| 388 if (uHash == pInfo->uHash) { | |
| 389 return pInfo; | |
| 390 } else if (uHash < pInfo->uHash) { | |
| 391 iEnd = iMid - 1; | |
| 392 } else { | |
| 393 iStart = iMid + 1; | |
| 394 } | |
| 395 } while (iStart <= iEnd); | |
| 396 iElementIndex = scriptIndex->wParentIndex; | |
| 397 } | |
| 398 return NULL; | |
| 399 } | |
| 400 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( | |
| 401 XFA_ELEMENT eElement, | |
| 402 const CFX_WideStringC& wsAttributeName) { | |
| 403 int32_t iLength = wsAttributeName.GetLength(); | |
| 404 if (iLength == 0) { | |
| 405 return NULL; | |
| 406 } | |
| 407 int32_t iElementIndex = eElement; | |
| 408 while (iElementIndex != -1) { | |
| 409 XFA_LPCSCRIPTHIERARCHY scriptIndex = g_XFAScriptIndex + iElementIndex; | |
| 410 int32_t icount = scriptIndex->wAttributeCount; | |
| 411 if (icount == 0) { | |
| 412 iElementIndex = scriptIndex->wParentIndex; | |
| 413 continue; | |
| 414 } | |
| 415 uint32_t uHash = FX_HashCode_String_GetW(wsAttributeName.GetPtr(), iLength); | |
| 416 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; | |
| 417 do { | |
| 418 int32_t iMid = (iStart + iEnd) / 2; | |
| 419 const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid; | |
| 420 if (uHash == pInfo->uHash) { | |
| 421 return pInfo; | |
| 422 } else if (uHash < pInfo->uHash) { | |
| 423 iEnd = iMid - 1; | |
| 424 } else { | |
| 425 iStart = iMid + 1; | |
| 426 } | |
| 427 } while (iStart <= iEnd); | |
| 428 iElementIndex = scriptIndex->wParentIndex; | |
| 429 } | |
| 430 return NULL; | |
| 431 } | |
| 432 void CXFA_Measurement::Set(const CFX_WideStringC& wsMeasure) { | |
| 433 if (wsMeasure.IsEmpty()) { | |
| 434 m_fValue = 0; | |
| 435 m_eUnit = XFA_UNIT_Unknown; | |
| 436 return; | |
| 437 } | |
| 438 int32_t iUsedLen = 0; | |
| 439 int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0; | |
| 440 FX_FLOAT fValue = FX_wcstof(wsMeasure.GetPtr() + iOffset, | |
| 441 wsMeasure.GetLength() - iOffset, &iUsedLen); | |
| 442 XFA_UNIT eUnit = GetUnit(wsMeasure.Mid(iOffset + iUsedLen)); | |
| 443 Set(fValue, eUnit); | |
| 444 } | |
| 445 FX_BOOL CXFA_Measurement::ToString(CFX_WideString& wsMeasure) const { | |
| 446 switch (GetUnit()) { | |
| 447 case XFA_UNIT_Mm: | |
| 448 wsMeasure.Format(L"%.8gmm", GetValue()); | |
| 449 return TRUE; | |
| 450 case XFA_UNIT_Pt: | |
| 451 wsMeasure.Format(L"%.8gpt", GetValue()); | |
| 452 return TRUE; | |
| 453 case XFA_UNIT_In: | |
| 454 wsMeasure.Format(L"%.8gin", GetValue()); | |
| 455 return TRUE; | |
| 456 case XFA_UNIT_Cm: | |
| 457 wsMeasure.Format(L"%.8gcm", GetValue()); | |
| 458 return TRUE; | |
| 459 case XFA_UNIT_Mp: | |
| 460 wsMeasure.Format(L"%.8gmp", GetValue()); | |
| 461 return TRUE; | |
| 462 case XFA_UNIT_Pc: | |
| 463 wsMeasure.Format(L"%.8gpc", GetValue()); | |
| 464 return TRUE; | |
| 465 case XFA_UNIT_Em: | |
| 466 wsMeasure.Format(L"%.8gem", GetValue()); | |
| 467 return TRUE; | |
| 468 case XFA_UNIT_Percent: | |
| 469 wsMeasure.Format(L"%.8g%%", GetValue()); | |
| 470 return TRUE; | |
| 471 default: | |
| 472 wsMeasure.Format(L"%.8g", GetValue()); | |
| 473 return FALSE; | |
| 474 } | |
| 475 } | |
| 476 FX_BOOL CXFA_Measurement::ToUnit(XFA_UNIT eUnit, FX_FLOAT& fValue) const { | |
| 477 fValue = GetValue(); | |
| 478 XFA_UNIT eFrom = GetUnit(); | |
| 479 if (eFrom == eUnit) { | |
| 480 return TRUE; | |
| 481 } | |
| 482 switch (eFrom) { | |
| 483 case XFA_UNIT_Pt: | |
| 484 break; | |
| 485 case XFA_UNIT_Mm: | |
| 486 fValue *= 72 / 2.54f / 10; | |
| 487 break; | |
| 488 case XFA_UNIT_In: | |
| 489 fValue *= 72; | |
| 490 break; | |
| 491 case XFA_UNIT_Cm: | |
| 492 fValue *= 72 / 2.54f; | |
| 493 break; | |
| 494 case XFA_UNIT_Mp: | |
| 495 fValue *= 0.001f; | |
| 496 break; | |
| 497 case XFA_UNIT_Pc: | |
| 498 fValue *= 12.0f; | |
| 499 break; | |
| 500 default: | |
| 501 fValue = 0; | |
| 502 return FALSE; | |
| 503 } | |
| 504 switch (eUnit) { | |
| 505 case XFA_UNIT_Pt: | |
| 506 return TRUE; | |
| 507 case XFA_UNIT_Mm: | |
| 508 fValue /= 72 / 2.54f / 10; | |
| 509 return TRUE; | |
| 510 case XFA_UNIT_In: | |
| 511 fValue /= 72; | |
| 512 return TRUE; | |
| 513 case XFA_UNIT_Cm: | |
| 514 fValue /= 72 / 2.54f; | |
| 515 return TRUE; | |
| 516 case XFA_UNIT_Mp: | |
| 517 fValue /= 0.001f; | |
| 518 return TRUE; | |
| 519 case XFA_UNIT_Pc: | |
| 520 fValue /= 12.0f; | |
| 521 return TRUE; | |
| 522 default: | |
| 523 fValue = 0; | |
| 524 return FALSE; | |
| 525 } | |
| 526 return FALSE; | |
| 527 } | |
| 528 XFA_UNIT CXFA_Measurement::GetUnit(const CFX_WideStringC& wsUnit) { | |
| 529 if (wsUnit == FX_WSTRC(L"mm")) { | |
| 530 return XFA_UNIT_Mm; | |
| 531 } else if (wsUnit == FX_WSTRC(L"pt")) { | |
| 532 return XFA_UNIT_Pt; | |
| 533 } else if (wsUnit == FX_WSTRC(L"in")) { | |
| 534 return XFA_UNIT_In; | |
| 535 } else if (wsUnit == FX_WSTRC(L"cm")) { | |
| 536 return XFA_UNIT_Cm; | |
| 537 } else if (wsUnit == FX_WSTRC(L"pc")) { | |
| 538 return XFA_UNIT_Pc; | |
| 539 } else if (wsUnit == FX_WSTRC(L"mp")) { | |
| 540 return XFA_UNIT_Mp; | |
| 541 } else if (wsUnit == FX_WSTRC(L"em")) { | |
| 542 return XFA_UNIT_Em; | |
| 543 } else if (wsUnit == FX_WSTRC(L"%")) { | |
| 544 return XFA_UNIT_Percent; | |
| 545 } else { | |
| 546 return XFA_UNIT_Unknown; | |
| 547 } | |
| 548 } | |
| 549 IFX_Stream* XFA_CreateWideTextRead(const CFX_WideString& wsBuffer) { | |
| 550 return new CXFA_WideTextRead(wsBuffer); | |
| 551 } | |
| 552 CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer) | |
| 553 : m_wsBuffer(wsBuffer), m_iPosition(0), m_iRefCount(1) {} | |
| 554 void CXFA_WideTextRead::Release() { | |
| 555 if (--m_iRefCount < 1) { | |
| 556 delete this; | |
| 557 } | |
| 558 } | |
| 559 IFX_Stream* CXFA_WideTextRead::Retain() { | |
| 560 m_iRefCount++; | |
| 561 return this; | |
| 562 } | |
| 563 FX_DWORD CXFA_WideTextRead::GetAccessModes() const { | |
| 564 return FX_STREAMACCESS_Read | FX_STREAMACCESS_Text; | |
| 565 } | |
| 566 int32_t CXFA_WideTextRead::GetLength() const { | |
| 567 return m_wsBuffer.GetLength() * sizeof(FX_WCHAR); | |
| 568 } | |
| 569 int32_t CXFA_WideTextRead::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | |
| 570 switch (eSeek) { | |
| 571 case FX_STREAMSEEK_Begin: | |
| 572 m_iPosition = iOffset; | |
| 573 break; | |
| 574 case FX_STREAMSEEK_Current: | |
| 575 m_iPosition += iOffset; | |
| 576 break; | |
| 577 case FX_STREAMSEEK_End: | |
| 578 m_iPosition = m_wsBuffer.GetLength() + iOffset; | |
| 579 break; | |
| 580 } | |
| 581 if (m_iPosition < 0) { | |
| 582 m_iPosition = 0; | |
| 583 } | |
| 584 if (m_iPosition > m_wsBuffer.GetLength()) { | |
| 585 m_iPosition = m_wsBuffer.GetLength(); | |
| 586 } | |
| 587 return GetPosition(); | |
| 588 } | |
| 589 int32_t CXFA_WideTextRead::GetPosition() { | |
| 590 return m_iPosition * sizeof(FX_WCHAR); | |
| 591 } | |
| 592 FX_BOOL CXFA_WideTextRead::IsEOF() const { | |
| 593 return m_iPosition >= m_wsBuffer.GetLength(); | |
| 594 } | |
| 595 int32_t CXFA_WideTextRead::ReadString(FX_WCHAR* pStr, | |
| 596 int32_t iMaxLength, | |
| 597 FX_BOOL& bEOS, | |
| 598 int32_t const* pByteSize) { | |
| 599 if (iMaxLength > m_wsBuffer.GetLength() - m_iPosition) { | |
| 600 iMaxLength = m_wsBuffer.GetLength() - m_iPosition; | |
| 601 } | |
| 602 FXSYS_wcsncpy(pStr, (const FX_WCHAR*)m_wsBuffer + m_iPosition, iMaxLength); | |
| 603 m_iPosition += iMaxLength; | |
| 604 bEOS = IsEOF(); | |
| 605 return iMaxLength; | |
| 606 } | |
| 607 FX_WORD CXFA_WideTextRead::GetCodePage() const { | |
| 608 return (sizeof(FX_WCHAR) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; | |
| 609 } | |
| 610 FX_WORD CXFA_WideTextRead::SetCodePage(FX_WORD wCodePage) { | |
| 611 return GetCodePage(); | |
| 612 } | |
| OLD | NEW |