void PDF_ReplaceAbbr(CPDF_Object* pObj) { switch (pObj->GetType()) { case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pDict = pObj->AsDictionary(); for (const auto& it : *pDict) { CFX_ByteString key = it.first; CPDF_Object* value = it.second; CFX_ByteStringC fullname = PDF_FindFullName( PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); if (!fullname.IsEmpty()) { pDict->ReplaceKey(key, fullname); key = fullname; } if (value->IsName()) { CFX_ByteString name = value->GetString(); fullname = PDF_FindFullName(PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); if (!fullname.IsEmpty()) { pDict->SetAtName(key, fullname); } } else { PDF_ReplaceAbbr(value); } } break; } case PDFOBJ_ARRAY: { CPDF_Array* pArray = pObj->AsArray(); for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); if (pElement->IsName()) { CFX_ByteString name = pElement->GetString(); CFX_ByteStringC fullname = PDF_FindFullName( PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); if (!fullname.IsEmpty()) { pArray->SetAt(i, new CPDF_Name(fullname)); } } else { PDF_ReplaceAbbr(pElement); } } break; } } }
void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); CFX_ByteString csValue = csOn; if (csValue.IsEmpty()) { csValue = "Yes"; } if (csValue == "Off") { csValue = "Yes"; } CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off"); if (csAS != "Off") { m_pWidgetDict->SetAtName("AS", csValue); } CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); if (pAP == NULL) { return; } FX_POSITION pos1 = pAP->GetStartPos(); while (pos1) { CFX_ByteString csKey1; CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1); if (pObj1 == NULL) { continue; } CPDF_Object* pObjDirect1 = pObj1->GetDirect(); if (pObjDirect1->GetType() != PDFOBJ_DICTIONARY) { continue; } CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)pObjDirect1; FX_POSITION pos2 = pSubDict->GetStartPos(); while (pos2) { CFX_ByteString csKey2; CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2); if (pObj2 == NULL) { continue; } if (csKey2 != "Off") { pSubDict->ReplaceKey(csKey2, csValue); break; } } } }
void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); CFX_ByteString csValue = csOn; if (csValue.IsEmpty()) { csValue = "Yes"; } if (csValue == "Off") { csValue = "Yes"; } CFX_ByteString csAS = m_pWidgetDict->GetStringBy("AS", "Off"); if (csAS != "Off") { m_pWidgetDict->SetAtName("AS", csValue); } CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); if (!pAP) { return; } for (const auto& it : *pAP) { CPDF_Object* pObj1 = it.second; if (!pObj1) { continue; } CPDF_Object* pObjDirect1 = pObj1->GetDirect(); CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); if (!pSubDict) continue; auto subdict_it = pSubDict->begin(); while (subdict_it != pSubDict->end()) { const CFX_ByteString& csKey2 = subdict_it->first; CPDF_Object* pObj2 = subdict_it->second; ++subdict_it; if (!pObj2) { continue; } if (csKey2 != "Off") { pSubDict->ReplaceKey(csKey2, csValue); break; } } } }