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

Commit

Permalink
[core] Fix clang-format error
Browse files Browse the repository at this point in the history
  • Loading branch information
zmiao committed Sep 26, 2019
1 parent 2aacede commit 3d89500
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 64 deletions.
115 changes: 56 additions & 59 deletions src/mbgl/text/glyph_pbf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,91 +21,88 @@ std::vector<Glyph> parseGlyphPBF(const GlyphRange& glyphRange, const std::string

while (glyph_pbf.next()) {
switch (glyph_pbf.tag()) {
case 1: // id
glyph.id = glyph_pbf.get_uint32();
hasID = true;
break;
case 2: // bitmap
glyphData = glyph_pbf.get_view();
break;
case 3: // width
glyph.metrics.width = glyph_pbf.get_uint32();
hasWidth = true;
break;
case 4: // height
glyph.metrics.height = glyph_pbf.get_uint32();
hasHeight = true;
break;
case 5: // left
glyph.metrics.left = glyph_pbf.get_sint32();
hasLeft = true;
break;
case 6: // top
glyph.metrics.top = glyph_pbf.get_sint32();
hasTop = true;
break;
case 7: // advance
glyph.metrics.advance = glyph_pbf.get_uint32();
hasAdvance = true;
break;
default:
glyph_pbf.skip();
break;
case 1: // id
glyph.id = glyph_pbf.get_uint32();
hasID = true;
break;
case 2: // bitmap
glyphData = glyph_pbf.get_view();
break;
case 3: // width
glyph.metrics.width = glyph_pbf.get_uint32();
hasWidth = true;
break;
case 4: // height
glyph.metrics.height = glyph_pbf.get_uint32();
hasHeight = true;
break;
case 5: // left
glyph.metrics.left = glyph_pbf.get_sint32();
hasLeft = true;
break;
case 6: // top
glyph.metrics.top = glyph_pbf.get_sint32();
hasTop = true;
break;
case 7: // advance
glyph.metrics.advance = glyph_pbf.get_uint32();
hasAdvance = true;
break;
default:
glyph_pbf.skip();
break;
}
}

// Only treat this glyph as a correct glyph if it has all required fields. It also
// needs to satisfy a few metrics conditions that ensure that the glyph isn't bogus.
// All other glyphs are malformed. We're also discarding all glyphs that are outside
// the expected glyph range.
if (!hasID || !hasWidth || !hasHeight || !hasLeft || !hasTop || !hasAdvance ||
glyph.metrics.width >= 256 || glyph.metrics.height >= 256 ||
glyph.metrics.left < -128 || glyph.metrics.left >= 128 ||
glyph.metrics.top < -128 || glyph.metrics.top >= 128 ||
glyph.metrics.advance >= 256 || glyph.id < glyphRange.first ||
glyph.id > glyphRange.second) {
if (!hasID || !hasWidth || !hasHeight || !hasLeft || !hasTop || !hasAdvance || glyph.metrics.width >= 256 ||
glyph.metrics.height >= 256 || glyph.metrics.left < -128 || glyph.metrics.left >= 128 ||
glyph.metrics.top < -128 || glyph.metrics.top >= 128 || glyph.metrics.advance >= 256 ||
glyph.id < glyphRange.first || glyph.id > glyphRange.second) {
return;
}

// If the area of width/height is non-zero, we need to adjust the expected size
// with the implicit border size, otherwise we expect there to be no bitmap at all.
if (glyph.metrics.width && glyph.metrics.height) {
const Size size{ glyph.metrics.width + 2 * Glyph::borderSize,
glyph.metrics.height + 2 * Glyph::borderSize };
const Size size{glyph.metrics.width + 2 * Glyph::borderSize,
glyph.metrics.height + 2 * Glyph::borderSize};

if (size.area() != glyphData.size()) {
return;
}

glyph.bitmap = AlphaImage(size, reinterpret_cast<const uint8_t*>(glyphData.data()),
glyphData.size());
glyph.bitmap = AlphaImage(size, reinterpret_cast<const uint8_t*>(glyphData.data()), glyphData.size());
}

result.push_back(std::move(glyph));
};

double ascender{ 0.0 }, descender{ 0.0 };
uint16_t count{ 0 };
double ascender{0.0}, descender{0.0};
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 = fontstack_pbf.get_double();
break;
}
case 5: {
descender = fontstack_pbf.get_double();
break;
}
default: {
fontstack_pbf.skip();
break;
}
case 3: {
readGlyphMetrics(fontstack_pbf);
++count;
break;
}
case 4: {
ascender = fontstack_pbf.get_double();
break;
}
case 5: {
descender = fontstack_pbf.get_double();
break;
}
default: {
fontstack_pbf.skip();
break;
}
}
}
if (ascender != 0.0 || descender != 0.0) {
Expand Down
9 changes: 4 additions & 5 deletions src/mbgl/text/shaping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,17 @@ void shapeLines(Shaping& shaping,
// from the horizontal baseline to the highest ‘character’ coordinate in a font face.
// Since we're laying out at 24 points, we need also calculate how much it will move
// when we scale up or down.
const double baselineOffset = -glyph.metrics.ascender * section.scale +
(lineMaxScale - section.scale) * util::ONE_EM;
const double baselineOffset =
-glyph.metrics.ascender * section.scale + (lineMaxScale - section.scale) * util::ONE_EM;

if (writingMode == WritingModeType::Horizontal ||
// Don't verticalize glyphs that have no upright orientation if vertical placement is disabled.
(!allowVerticalPlacement && !util::i18n::hasUprightVerticalOrientation(codePoint)) ||
// If vertical placement is ebabled, don't verticalize glyphs that
// are from complex text layout script, or whitespaces.
(allowVerticalPlacement && (util::i18n::isWhitespace(codePoint) || util::i18n::isCharInComplexShapingScript(codePoint)))) {
shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false,
section.fontStackHash, section.scale,
sectionIndex);
shaping.positionedGlyphs.emplace_back(
codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale, sectionIndex);
x += glyph.metrics.advance * section.scale + spacing;
} else {
shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, true, section.fontStackHash, section.scale, sectionIndex);
Expand Down

0 comments on commit 3d89500

Please sign in to comment.