31 return scaled * 1000 / emSize;
36 if (advances.
empty()) {
40 SkScalar currentAdvance = advances[0];
41 SkScalar currentModeAdvance = advances[0];
42 size_t currentCount = 1;
43 size_t currentModeCount = 1;
45 for (
size_t i = 1;
i < advances.
size(); ++
i) {
46 if (advances[
i] == currentAdvance) {
49 if (currentCount > currentModeCount) {
50 currentModeAdvance = currentAdvance;
51 currentModeCount = currentCount;
53 currentAdvance = advances[
i];
57 return currentCount > currentModeCount ? currentAdvance : currentModeAdvance;
64 int32_t* defaultAdvance) {
99 std::vector<SkGlyphID> glyphIDs;
101 glyphIDs.push_back(
SkToU16(index));
106 auto advances = std::unique_ptr<SkScalar[]>(
new SkScalar[
glyphs.size()]);
111 size_t numIntAdvances = 0;
114 if ((int32_t)currentAdvance == currentAdvance) {
115 advances[numIntAdvances++] = currentAdvance;
118 std::sort(advances.get(), advances.get() + numIntAdvances);
119 int32_t modeAdvance = (int32_t)find_mode_or_0(
SkSpan(advances.get(), numIntAdvances));
120 *defaultAdvance = modeAdvance;
123 for (
size_t i = 0;
i <
glyphs.size(); ++
i) {
127 for (
size_t i = 0;
i <
glyphs.size(); ++
i) {
131 if (advance == modeAdvance) {
138 for (; j <
glyphs.size(); ++j) {
139 SkScalar next_advance = advances[j];
140 if (advance != next_advance) {
147 result->appendScalar(advance);
156 advanceArray->appendScalar(advance);
158 for (; j <
glyphs.size(); ++j) {
159 advance = advances[j];
162 if (advance == modeAdvance) {
166 int dontCares =
glyphs[j]->getGlyphID() -
glyphs[j - 1]->getGlyphID() - 1;
168 if (dontCares >= 4) {
174 if (j + 1 <
glyphs.size()) {
175 next_advance = advances[j+1];
176 int next_dontCares =
glyphs[j+1]->getGlyphID() -
glyphs[j]->getGlyphID() - 1;
177 if (advance == next_advance && dontCares + next_dontCares >= 4) {
183 if (j + 2 <
glyphs.size() && advance == next_advance) {
184 next_advance = advances[j+2];
185 if (advance == next_advance) {
190 while (dontCares --> 0) {
191 advanceArray->appendScalar(0);
193 advanceArray->appendScalar(advance);
195 result->appendObject(std::move(advanceArray));
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
std::unique_ptr< SkPDFArray > SkPDFMakeCIDGlyphWidthsArray(const SkTypeface &typeface, const SkPDFGlyphUse &subset, int32_t *defaultAdvance)
static SkScalar from_font_units(SkScalar scaled, uint16_t emSize)
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
constexpr uint16_t SkToU16(S x)
void getSetValues(FN f) const
constexpr bool empty() const
constexpr size_t size() const
static SkStrikeSpec MakePDFVector(const SkTypeface &typeface, int *size)