Example #1
0
CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const
{
    if (m_Type == PDFOBJ_STRING) {
        return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap);
    } else if (m_Type == PDFOBJ_STREAM) {
        CPDF_StreamAcc stream;
        stream.LoadAllData((CPDF_Stream*)this, FALSE);
        CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap);
        return result;
    } else if (m_Type == PDFOBJ_NAME) {
        return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap);
    }
    return CFX_WideString();
}
CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const {
  if (const CPDF_String* pString = AsString())
    return PDF_DecodeText(pString->m_String, pCharMap);

  if (const CPDF_Stream* pStream = AsStream()) {
    CPDF_StreamAcc stream;
    stream.LoadAllData(pStream, FALSE);
    CFX_WideString result =
        PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap);
    return result;
  }
  if (const CPDF_Name* pName = AsName())
    return PDF_DecodeText(pName->m_Name, pCharMap);
  return CFX_WideString();
}
Example #3
0
static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict,
                                      CFX_WideString& csValue,
                                      CFX_ByteString& bsEncoding) {
  ASSERT(pFieldDict != NULL);
  CFX_ByteString csBValue = pFieldDict->GetString("V");
  int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]);
  int32_t i = 0;
  for (; i < iCount; ++i)
    if (bsEncoding == g_fieldEncoding[i].m_name) {
      break;
    }
  if (i < iCount) {
    CFX_CharMap* pCharMap =
        CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage);
    FXSYS_assert(pCharMap != NULL);
    csValue.ConvertFrom(csBValue, pCharMap);
    return;
  }
  CFX_ByteString csTemp = csBValue.Left(2);
  if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") {
    csValue = PDF_DecodeText(csBValue);
  } else {
    csValue = CFX_WideString::FromLocal(csBValue);
  }
}
Example #4
0
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long* buflen)
{
    if (!buffer)
        *buflen = 0;
    if (!document || index < 0) return NULL;
    CPDF_Document* pDoc = (CPDF_Document*)document;

    CPDF_Dictionary* pRoot = pDoc->GetRoot();
    if (!pRoot) return NULL;

    CPDF_Object* pDestObj = NULL;
    CFX_ByteString bsName;
    CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
    int count = nameTree.GetCount();
    if (index >= count) {
        CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
        if (!pDest) return NULL;
        if (index >= count + pDest->GetCount()) return NULL;
        index -= count;
        FX_POSITION pos = pDest->GetStartPos();
        int i = 0;
        while (pos) {
            pDestObj = pDest->GetNextElement(pos, bsName);
            if (!pDestObj) continue;
            if (i == index) break;
            i++;
        }
    } else {
        pDestObj = nameTree.LookupValue(index, bsName);
    }
    if (!pDestObj) return NULL;
    if (pDestObj->GetType() == PDFOBJ_DICTIONARY) {
        pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D"));
        if (!pDestObj) return NULL;
    }
    if (pDestObj->GetType() != PDFOBJ_ARRAY) return NULL;
    CFX_WideString wsName = PDF_DecodeText(bsName);
    CFX_ByteString utf16Name = wsName.UTF16LE_Encode();
    unsigned int len = utf16Name.GetLength();
    if (!buffer) {
        *buflen = len;
    } else if (*buflen >= len) {
        memcpy(buffer, utf16Name.c_str(), len);
        *buflen = len;
    } else {
        *buflen = -1;
    }
    return (FPDF_DEST)pDestObj;
}
Example #5
0
CFX_WideString CPDF_FormControl::GetExportValue() const {
    ASSERT(GetType() == CPDF_FormField::CheckBox ||
           GetType() == CPDF_FormField::RadioButton);
    CFX_ByteString csOn = GetOnStateName();
    if (GetType() == CPDF_FormField::RadioButton ||
            GetType() == CPDF_FormField::CheckBox) {
        if (CPDF_Array* pArray =
                    ToArray(FPDF_GetFieldAttr(m_pField->m_pDict, "Opt"))) {
            int iIndex = m_pField->GetControlIndex(this);
            csOn = pArray->GetStringAt(iIndex);
        }
    }
    if (csOn.IsEmpty())
        csOn = "Yes";
    return PDF_DecodeText(csOn);
}
Example #6
0
CFX_WideString CPDF_FormControl::GetExportValue()
{
    ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton);
    CFX_ByteString csOn = GetOnStateName();
    if (GetType() == CPDF_FormField::RadioButton || GetType() == CPDF_FormField::CheckBox) {
        CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
        if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
            int iIndex = m_pField->GetControlIndex(this);
            csOn = ((CPDF_Array*)pOpt)->GetString(iIndex);
        }
    }
    if (csOn.IsEmpty()) {
        csOn = "Yes";
    }
    CFX_WideString csWOn = PDF_DecodeText(csOn);
    return csWOn;
}
Example #7
0
FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
                                               FX_STRSIZE& nBufSize) {
  CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
  if (!pFDF)
    return TRUE;

  CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF");
  if (!pMainDict)
    return FALSE;

  CPDF_Array* pFields = pMainDict->GetArrayFor("Fields");
  if (!pFields)
    return FALSE;

  CFX_ByteTextBuf fdfEncodedData;
  for (uint32_t i = 0; i < pFields->GetCount(); i++) {
    CPDF_Dictionary* pField = pFields->GetDictAt(i);
    if (!pField)
      continue;
    CFX_WideString name;
    name = pField->GetUnicodeTextFor("T");
    CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
    CFX_ByteString csBValue = pField->GetStringFor("V");
    CFX_WideString csWValue = PDF_DecodeText(csBValue);
    CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);

    fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
    name_b.ReleaseBuffer();
    fdfEncodedData << "=";
    fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength());
    csValue_b.ReleaseBuffer();
    if (i != pFields->GetCount() - 1)
      fdfEncodedData << "&";
  }

  nBufSize = fdfEncodedData.GetLength();
  pBuf = FX_Alloc(uint8_t, nBufSize);
  FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
  return TRUE;
}
Example #8
0
CFX_WideString CPDF_Stream::GetUnicodeText() const {
  CPDF_StreamAcc stream;
  stream.LoadAllData(this, FALSE);
  return PDF_DecodeText(stream.GetData(), stream.GetSize());
}
Example #9
0
CFX_WideString CPDF_Name::GetUnicodeText() const {
  return PDF_DecodeText(m_Name);
}
Example #10
0
WideString CPDF_Stream::GetUnicodeText() const {
  auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(this);
  pAcc->LoadAllDataFiltered();
  return PDF_DecodeText(pAcc->GetData(), pAcc->GetSize());
}