MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CoreTextVisualRun

Method CoreTextVisualRun

src/os/macosx/string_osx.cpp:233–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font)
234{
235 this->glyphs.resize(CTRunGetGlyphCount(run));
236
237 /* Query map of glyphs to source string index. */
238 auto map = std::make_unique<CFIndex[]>(this->glyphs.size());
239 CTRunGetStringIndices(run, CFRangeMake(0, 0), map.get());
240
241 this->glyph_to_char.resize(this->glyphs.size());
242 for (size_t i = 0; i < this->glyph_to_char.size(); i++) this->glyph_to_char[i] = (int)map[i];
243
244 auto pts = std::make_unique<CGPoint[]>(this->glyphs.size());
245 CTRunGetPositions(run, CFRangeMake(0, 0), pts.get());
246 auto advs = std::make_unique<CGSize[]>(this->glyphs.size());
247 CTRunGetAdvances(run, CFRangeMake(0, 0), advs.get());
248 this->positions.reserve(this->glyphs.size());
249
250 /* Convert glyph array to our data type. At the same time, substitute
251 * the proper glyphs for our private sprite glyphs. */
252 auto gl = std::make_unique<CGGlyph[]>(this->glyphs.size());
253 CTRunGetGlyphs(run, CFRangeMake(0, 0), gl.get());
254 for (size_t i = 0; i < this->glyphs.size(); i++) {
255 if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END && (gl[i] == 0 || gl[i] == 3)) {
256 /* A glyph of 0 indicates not found, while apparently 3 is what char 0xFFFC maps to. */
257 this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]);
258 this->positions.emplace_back(pts[i].x, pts[i].x + advs[i].width - 1, (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2); // Align sprite font to centre
259 } else {
260 this->glyphs[i] = gl[i];
261 this->positions.emplace_back(pts[i].x, pts[i].x + advs[i].width - 1, pts[i].y);
262 }
263 }
264 this->total_advance = (int)std::ceil(CTRunGetTypographicBounds(run, CFRangeMake(0, 0), nullptr, nullptr, nullptr));
265}
266
267/**
268 * Get the height of the line.

Callers

nothing calls this directly

Calls 8

ScaleSpriteTradFunction · 0.85
resizeMethod · 0.80
reserveMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45
MapCharToGlyphMethod · 0.45
GetHeightMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected