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