From ddbd3929030e46f00c30157617e04a4bcb53a2af Mon Sep 17 00:00:00 2001 From: zmiao Date: Wed, 2 Oct 2019 11:46:42 +0300 Subject: [core] nit fix --- src/mbgl/text/glyph_pbf.cpp | 6 ++---- src/mbgl/text/shaping.cpp | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp index 8ed48d08c1..dd9fe1638f 100644 --- a/src/mbgl/text/glyph_pbf.cpp +++ b/src/mbgl/text/glyph_pbf.cpp @@ -83,18 +83,16 @@ std::tuple, int32_t, int32_t> parseGlyphPBF(const GlyphRange& glyphs.push_back(std::move(glyph)); }; - uint16_t count{0}; auto fontstack_pbf = glyphs_pbf.get_message(); while (fontstack_pbf.next()) { switch (fontstack_pbf.tag()) { case 3: { readGlyphMetrics(fontstack_pbf); - ++count; break; } case 4: { // ascender value for one fontstack shall keep the same, if different values appear, set ascender to - // be 0. + // be 0/invalid. const auto value = fontstack_pbf.get_sint32(); if (!ascenderSet) { ascender = value; @@ -106,7 +104,7 @@ std::tuple, int32_t, int32_t> parseGlyphPBF(const GlyphRange& } case 5: { // descender value for one fontstack shall keep the same, if different values appear, set descender - // to be 0. + // to be 0/invalid. const auto value = fontstack_pbf.get_sint32(); if (!descenderSet) { descender = value; diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 337dd613dd..42b29b9f8d 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -360,7 +360,7 @@ void shapeLines(Shaping& shaping, continue; } - float biggestHeight{0}, baselineOffset{0}; + float biggestHeight{0.0f}, baselineOffset{0.0f}; std::size_t lineStartIndex = shaping.positionedGlyphs.size(); for (std::size_t i = 0; i < line.length(); i++) { const std::size_t sectionIndex = line.getSectionIndex(i); @@ -377,13 +377,14 @@ void shapeLines(Shaping& shaping, const Glyph& glyph = **it->second; - double ascender{0}, descender{0}, glyphOffset{0}; + float ascender{0.0f}, descender{0.0f}, glyphOffset{0.0f}; // In order to make different fonts aligned, they must share a general baseline that aligns with every - // font's real baseline. Glyph's position is counted from the top left corner, where is the ascender line - // starts. Since ascender is above the baseline, the glyphOffset is the negative shift. In order to make all - // the glyphs aligned with shaping box, for each line, we lock the heighest glyph (with scale) locating - // at the middle of the line, which will lead to a baseline shift. Then adjust the whole line with the - // baseline offset we calculated from the shift. + // font's real baseline. Glyph's offset is counted from the top left corner, where is the ascender line + // starts. First of all, every glyph's baseline lies on the middle line of each shaping line. Since ascender + // is above the baseline, the glyphOffset is the negative shift. Then, in order to make glyphs fit in the + // shaping box, for each line, we shift the glyph with biggest height(with scale) to make its middle line + // lie on the middle line of the line, which will lead to a baseline shift. Then adjust the whole line with + // the baseline offset we calculated from the shift. if (hasBaseline) { assert(glyphs->second.ascender && glyphs->second.descender); ascender = std::abs(glyphs->second.ascender.value()); @@ -395,9 +396,9 @@ void shapeLines(Shaping& shaping, } glyphOffset = -ascender * section.scale; } else { - // If font's baseline is not applicable, fall back to use a default baseline - // offset, see shaping.yOffset. Since we're laying out at 24 points, we need also calculate how much it - // will move when we scale up or down. + // If font's baseline is not applicable, fall back to use a default baseline offset, see + // Shaping::yOffset. Since we're laying out at 24 points, we need also calculate how much it will move + // when we scale up or down. glyphOffset = Shaping::yOffset + (lineMaxScale - section.scale) * util::ONE_EM; } -- cgit v1.2.1