Commit 2a33db917fad7e8769ae00319d7ece83eec42d27

Authored by m-holger
1 parent 8aab6838

Refactor `FormNode`: remove unused `getFontFromResource` method and simplify fon…

…t resource handling in `generateTextAppearance`.
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -877,16 +877,6 @@ namespace @@ -877,16 +877,6 @@ namespace
877 }; 877 };
878 } // namespace 878 } // namespace
879 879
880 -QPDFObjectHandle  
881 -FormNode::getFontFromResource(QPDFObjectHandle resources, std::string const& name)  
882 -{  
883 - QPDFObjectHandle result;  
884 - if (resources.isDictionary() && resources.getKey("/Font").isDictionary() &&  
885 - resources.getKey("/Font").hasKey(name)) {  
886 - result = resources.getKey("/Font").getKey(name);  
887 - }  
888 - return result;  
889 -}  
890 880
891 void 881 void
892 FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) 882 FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
@@ -961,9 +951,9 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) @@ -961,9 +951,9 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
961 if (!font_name.empty()) { 951 if (!font_name.empty()) {
962 // See if the font is encoded with something we know about. 952 // See if the font is encoded with something we know about.
963 Dictionary resources = AS.getDict()["/Resources"]; 953 Dictionary resources = AS.getDict()["/Resources"];
964 - Dictionary font = getFontFromResource(resources, font_name); 954 + Dictionary font = resources["/Font"][font_name];
965 if (!font) { 955 if (!font) {
966 - font = getFontFromResource(getDefaultResources(), font_name); 956 + font = getDefaultResources()["/Font"][font_name];
967 if (resources) { 957 if (resources) {
968 if (resources.indirect()) { 958 if (resources.indirect()) {
969 resources = resources.qpdf()->makeIndirectObject(resources.copy()); 959 resources = resources.qpdf()->makeIndirectObject(resources.copy());
@@ -972,7 +962,7 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) @@ -972,7 +962,7 @@ FormNode::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
972 // Use mergeResources to force /Font to be local 962 // Use mergeResources to force /Font to be local
973 QPDFObjectHandle res = resources; 963 QPDFObjectHandle res = resources;
974 res.mergeResources(Dictionary({{"/Font", Dictionary::empty()}})); 964 res.mergeResources(Dictionary({{"/Font", Dictionary::empty()}}));
975 - res.getKey("/Font").replaceKey(font_name, font); 965 + res.getKey("/Font").replace(font_name, font);
976 } 966 }
977 } 967 }
978 968
libqpdf/qpdf/AcroForm.hh
@@ -769,8 +769,6 @@ namespace qpdf::impl @@ -769,8 +769,6 @@ namespace qpdf::impl
769 void setRadioButtonValue(QPDFObjectHandle name); 769 void setRadioButtonValue(QPDFObjectHandle name);
770 void setCheckBoxValue(bool value); 770 void setCheckBoxValue(bool value);
771 void generateTextAppearance(QPDFAnnotationObjectHelper&); 771 void generateTextAppearance(QPDFAnnotationObjectHelper&);
772 - QPDFObjectHandle  
773 - getFontFromResource(QPDFObjectHandle resources, std::string const& font_name);  
774 772
775 static const QPDFObjectHandle null_oh; 773 static const QPDFObjectHandle null_oh;
776 }; // class FormNode 774 }; // class FormNode