Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 32dd8e6

Browse files
committed
[core] nit fix
1 parent 8a5a1e1 commit 32dd8e6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/mbgl/text/glyph_pbf.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,16 @@ std::tuple<std::vector<Glyph>, int32_t, int32_t> parseGlyphPBF(const GlyphRange&
8383
glyphs.push_back(std::move(glyph));
8484
};
8585

86-
uint16_t count{0};
8786
auto fontstack_pbf = glyphs_pbf.get_message();
8887
while (fontstack_pbf.next()) {
8988
switch (fontstack_pbf.tag()) {
9089
case 3: {
9190
readGlyphMetrics(fontstack_pbf);
92-
++count;
9391
break;
9492
}
9593
case 4: {
9694
// ascender value for one fontstack shall keep the same, if different values appear, set ascender to
97-
// be 0.
95+
// be 0/invalid.
9896
const auto value = fontstack_pbf.get_sint32();
9997
if (!ascenderSet) {
10098
ascender = value;
@@ -106,7 +104,7 @@ std::tuple<std::vector<Glyph>, int32_t, int32_t> parseGlyphPBF(const GlyphRange&
106104
}
107105
case 5: {
108106
// descender value for one fontstack shall keep the same, if different values appear, set descender
109-
// to be 0.
107+
// to be 0/invalid.
110108
const auto value = fontstack_pbf.get_sint32();
111109
if (!descenderSet) {
112110
descender = value;

src/mbgl/text/shaping.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void shapeLines(Shaping& shaping,
360360
continue;
361361
}
362362

363-
float biggestHeight{0}, baselineOffset{0};
363+
float biggestHeight{0.0f}, baselineOffset{0.0f};
364364
std::size_t lineStartIndex = shaping.positionedGlyphs.size();
365365
for (std::size_t i = 0; i < line.length(); i++) {
366366
const std::size_t sectionIndex = line.getSectionIndex(i);
@@ -377,13 +377,14 @@ void shapeLines(Shaping& shaping,
377377

378378
const Glyph& glyph = **it->second;
379379

380-
double ascender{0}, descender{0}, glyphOffset{0};
380+
float ascender{0.0f}, descender{0.0f}, glyphOffset{0.0f};
381381
// In order to make different fonts aligned, they must share a general baseline that aligns with every
382-
// font's real baseline. Glyph's position is counted from the top left corner, where is the ascender line
383-
// starts. Since ascender is above the baseline, the glyphOffset is the negative shift. In order to make all
384-
// the glyphs aligned with shaping box, for each line, we lock the heighest glyph (with scale) locating
385-
// at the middle of the line, which will lead to a baseline shift. Then adjust the whole line with the
386-
// baseline offset we calculated from the shift.
382+
// font's real baseline. Glyph's offset is counted from the top left corner, where is the ascender line
383+
// starts. First of all, every glyph's baseline lies on the middle line of each shaping line. Since ascender
384+
// is above the baseline, the glyphOffset is the negative shift. Then, in order to make glyphs fit in the
385+
// shaping box, for each line, we shift the glyph with biggest height(with scale) to make its middle line
386+
// lie on the middle line of the line, which will lead to a baseline shift. Then adjust the whole line with
387+
// the baseline offset we calculated from the shift.
387388
if (hasBaseline) {
388389
assert(glyphs->second.ascender && glyphs->second.descender);
389390
ascender = std::abs(glyphs->second.ascender.value());
@@ -395,9 +396,9 @@ void shapeLines(Shaping& shaping,
395396
}
396397
glyphOffset = -ascender * section.scale;
397398
} else {
398-
// If font's baseline is not applicable, fall back to use a default baseline
399-
// offset, see shaping.yOffset. Since we're laying out at 24 points, we need also calculate how much it
400-
// will move when we scale up or down.
399+
// If font's baseline is not applicable, fall back to use a default baseline offset, see
400+
// Shaping::yOffset. Since we're laying out at 24 points, we need also calculate how much it will move
401+
// when we scale up or down.
401402
glyphOffset = Shaping::yOffset + (lineMaxScale - section.scale) * util::ONE_EM;
402403
}
403404

0 commit comments

Comments
 (0)