Example #1
0
void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
  if (nLevel > nMaxRecursion)
    return;
  if (!pFieldDict)
    return;

  uint32_t dwParentObjNum = pFieldDict->GetObjNum();
  CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids");
  if (!pKids) {
    AddTerminalField(pFieldDict);
    return;
  }

  CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0);
  if (!pFirstKid)
    return;

  if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
    for (size_t i = 0; i < pKids->GetCount(); i++) {
      CPDF_Dictionary* pChildDict = pKids->GetDictAt(i);
      if (pChildDict) {
        if (pChildDict->GetObjNum() != dwParentObjNum)
          LoadField(pChildDict, nLevel + 1);
      }
    }
  } else {
    AddTerminalField(pFieldDict);
  }
}
Example #2
0
void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
  if (nLevel > nMaxRecursion) {
    return;
  }
  if (pFieldDict == NULL) {
    return;
  }
  FX_DWORD dwParentObjNum = pFieldDict->GetObjNum();
  CPDF_Array* pKids = pFieldDict->GetArray("Kids");
  if (!pKids) {
    AddTerminalField(pFieldDict);
    return;
  }
  CPDF_Dictionary* pFirstKid = pKids->GetDict(0);
  if (pFirstKid == NULL) {
    return;
  }
  if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
    for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
      CPDF_Dictionary* pChildDict = pKids->GetDict(i);
      if (pChildDict) {
        if (pChildDict->GetObjNum() != dwParentObjNum) {
          LoadField(pChildDict, nLevel + 1);
        }
      }
    }
  } else {
    AddTerminalField(pFieldDict);
  }
}
Example #3
0
CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bGenerateAP)
    : CFX_PrivateData(),
      m_pDocument(pDocument),
      m_bGenerateAP(bGenerateAP),
      m_pFormDict(nullptr),
      m_pFieldTree(new CFieldTree),
      m_pFormNotify(nullptr),
      m_bUpdated(FALSE) {
  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
  if (!pRoot)
    return;

  m_pFormDict = pRoot->GetDict("AcroForm");
  if (!m_pFormDict)
    return;

  CPDF_Array* pFields = m_pFormDict->GetArray("Fields");
  if (!pFields)
    return;

  int count = pFields->GetCount();
  for (int i = 0; i < count; i++) {
    LoadField(pFields->GetDict(i));
  }
}
Example #4
0
void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
  CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
  if (!pPageDict)
    return;

  CPDF_Array* pAnnots = pPageDict->GetArrayFor("Annots");
  if (!pAnnots)
    return;

  for (size_t i = 0; i < pAnnots->GetCount(); i++) {
    CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i);
    if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget")
      LoadField(pAnnot, 0);
  }
}
Example #5
0
void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
  ASSERT(pPage != NULL);
  CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
  if (pPageDict == NULL) {
    return;
  }
  CPDF_Array* pAnnots = pPageDict->GetArray(FX_BSTRC("Annots"));
  if (pAnnots == NULL) {
    return;
  }
  int iAnnotCount = pAnnots->GetCount();
  for (int i = 0; i < iAnnotCount; i++) {
    CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
    if (pAnnot != NULL && pAnnot->GetString(FX_BSTRC("Subtype")) == "Widget") {
      LoadField(pAnnot);
    }
  }
}
Example #6
0
CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument)
    : m_pDocument(pDocument),
      m_pFormDict(nullptr),
      m_pFieldTree(new CFieldTree),
      m_pFormNotify(nullptr) {
  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
  if (!pRoot)
    return;

  m_pFormDict = pRoot->GetDictFor("AcroForm");
  if (!m_pFormDict)
    return;

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

  for (size_t i = 0; i < pFields->GetCount(); ++i)
    LoadField(pFields->GetDictAt(i), 0);
}
Example #7
0
int CAPETag::Analyze()
{
    // clean-up
    ID3_TAG ID3Tag;
    ClearFields();
    m_nTagBytes = 0;

    m_bAnalyzed = TRUE;

    // store the original location
    int nOriginalPosition = m_spIO->GetPosition();
    
    // check for a tag
    unsigned int nBytesRead;
    int nRetVal;
    m_bHasID3Tag = FALSE;
    m_bHasAPETag = FALSE;
    m_nAPETagVersion = -1;
    m_spIO->Seek(-ID3_TAG_BYTES, FILE_END);
    nRetVal = m_spIO->Read((unsigned char *) &ID3Tag, sizeof(ID3_TAG), &nBytesRead);
    
    if ((nBytesRead == sizeof(ID3_TAG)) && (nRetVal == 0))
    {
        if (ID3Tag.Header[0] == 'T' && ID3Tag.Header[1] == 'A' && ID3Tag.Header[2] == 'G') 
        {
            m_bHasID3Tag = TRUE;
            m_nTagBytes += ID3_TAG_BYTES;
        }
    }
    
    // set the fields
    if (m_bHasID3Tag)
    {
        SetFieldID3String(APE_TAG_FIELD_ARTIST, ID3Tag.Artist, 30);
        SetFieldID3String(APE_TAG_FIELD_ALBUM, ID3Tag.Album, 30);
        SetFieldID3String(APE_TAG_FIELD_TITLE, ID3Tag.Title, 30);
        SetFieldID3String(APE_TAG_FIELD_COMMENT, ID3Tag.Comment, 28);
        SetFieldID3String(APE_TAG_FIELD_YEAR, ID3Tag.Year, 4);
        
        char cTemp[16]; sprintf(cTemp, "%d", ID3Tag.Track);
        SetFieldString(APE_TAG_FIELD_TRACK, cTemp, FALSE);

        if ((ID3Tag.Genre == GENRE_UNDEFINED) || (ID3Tag.Genre >= GENRE_COUNT)) 
            SetFieldString(APE_TAG_FIELD_GENRE, APE_TAG_GENRE_UNDEFINED);
        else 
            SetFieldString(APE_TAG_FIELD_GENRE, g_ID3Genre[ID3Tag.Genre]);
    }

    // try loading the APE tag
    if (m_bHasID3Tag == FALSE)
    {
        APE_TAG_FOOTER APETagFooter;
        m_spIO->Seek(-int(APE_TAG_FOOTER_BYTES), FILE_END);
        nRetVal = m_spIO->Read((unsigned char *) &APETagFooter, APE_TAG_FOOTER_BYTES, &nBytesRead);
        if ((nBytesRead == APE_TAG_FOOTER_BYTES) && (nRetVal == 0))
        {
            if (APETagFooter.GetIsValid(FALSE))
            {
                m_bHasAPETag = TRUE;
                m_nAPETagVersion = APETagFooter.GetVersion();

                int nRawFieldBytes = APETagFooter.GetFieldBytes();
                m_nTagBytes += APETagFooter.GetTotalTagBytes();
                
                CSmartPtr<char> spRawTag(new char [nRawFieldBytes], TRUE);
                m_spIO->Seek(-(APETagFooter.GetTotalTagBytes() - APETagFooter.GetFieldsOffset()), FILE_END);
                nRetVal = m_spIO->Read((unsigned char *) spRawTag.GetPtr(), nRawFieldBytes, &nBytesRead);

                if ((nRetVal == 0) && (nRawFieldBytes == int(nBytesRead)))
                {
                    // parse out the raw fields
                    int nLocation = 0;
                    for (int z = 0; z < APETagFooter.GetNumberFields(); z++)
                    {
                        int nMaximumFieldBytes = nRawFieldBytes - nLocation;
                        
                        int nBytes = 0;
                        if (LoadField(&spRawTag[nLocation], nMaximumFieldBytes, &nBytes) != ERROR_SUCCESS)
                        {
                            // if LoadField(...) fails, it means that the tag is corrupt (accidently or intentionally)
                            // we'll just bail out -- leaving the fields we've already set
                            break;
                        }
                        nLocation += nBytes;
                    }
                }
            }
        }
    }

    // restore the file pointer
    m_spIO->Seek(nOriginalPosition, FILE_BEGIN);
    
    return ERROR_SUCCESS;
}