|
@@ -63,12 +63,29 @@ PDFErrorOr<NonnullRefPtr<Type1Font>> Type1Font::create(Document* document, Nonnu
|
|
|
if (dict->contains(CommonNames::ToUnicode))
|
|
|
to_unicode = MUST(dict->get_stream(document, CommonNames::ToUnicode));
|
|
|
|
|
|
- return adopt_ref(*new Type1Font(to_unicode, encoding.release_nonnull()));
|
|
|
+ auto first_char = dict->get_value(CommonNames::FirstChar).get<int>();
|
|
|
+ auto last_char = dict->get_value(CommonNames::LastChar).get<int>();
|
|
|
+ auto widths_array = MUST(dict->get_array(document, CommonNames::Widths));
|
|
|
+
|
|
|
+ VERIFY(widths_array->size() == static_cast<size_t>(last_char - first_char + 1));
|
|
|
+
|
|
|
+ HashMap<u16, u16> widths;
|
|
|
+ for (size_t i = 0; i < widths_array->size(); i++)
|
|
|
+ widths.set(first_char + i, widths_array->at(i).get<int>());
|
|
|
+
|
|
|
+ u16 missing_width = 0;
|
|
|
+ auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
|
|
+ if (descriptor->contains(CommonNames::MissingWidth))
|
|
|
+ missing_width = descriptor->get_value(CommonNames::MissingWidth).get<int>();
|
|
|
+
|
|
|
+ return adopt_ref(*new Type1Font(to_unicode, encoding.release_nonnull(), widths, missing_width));
|
|
|
}
|
|
|
|
|
|
-Type1Font::Type1Font(RefPtr<StreamObject> to_unicode, NonnullRefPtr<Encoding> encoding)
|
|
|
+Type1Font::Type1Font(RefPtr<StreamObject> to_unicode, NonnullRefPtr<Encoding> encoding, HashMap<u16, u16> const& widths, u16 missing_width)
|
|
|
: m_to_unicode(to_unicode)
|
|
|
, m_encoding(encoding)
|
|
|
+ , m_widths(widths)
|
|
|
+ , m_missing_width(missing_width)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -81,4 +98,16 @@ u32 Type1Font::char_code_to_code_point(u16 char_code) const
|
|
|
return descriptor.code_point;
|
|
|
}
|
|
|
|
|
|
+float Type1Font::get_char_width(u16 char_code) const
|
|
|
+{
|
|
|
+ u16 width;
|
|
|
+ if (auto char_code_width = m_widths.get(char_code); char_code_width.has_value()) {
|
|
|
+ width = char_code_width.value();
|
|
|
+ } else {
|
|
|
+ width = m_missing_width;
|
|
|
+ }
|
|
|
+
|
|
|
+ return static_cast<float>(width) / 1000.0f;
|
|
|
+}
|
|
|
+
|
|
|
}
|