UNPKG

@lightningjs/renderer

Version:
69 lines 2.51 kB
/* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * * Copyright 2025 Comcast Cable Communications Management, LLC. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as SdfFontHandler from '../SdfFontHandler.js'; /** * Create a simple SDF font shaper */ export const createSdfFontShaper = () => ({ shapeText: function* (props, codepoints) { // Host paths on top const fontFamily = props.fontFamily; const fontSize = props.fontSize; const letterSpacing = props.letterSpacing; const fontData = SdfFontHandler.getFontData(fontFamily); if (fontData === null) return; const fontScale = fontSize / fontData.common.lineHeight; let prevCodepoint = 0; while (true) { const result = codepoints.next(); if (result.done) break; const codepoint = result.value; if (!codepoint) continue; // Get glyph data const glyph = SdfFontHandler.getGlyph(fontFamily, codepoint); if (glyph === null) { yield { mapped: false, codepoint, xAdvance: 0, }; continue; } // Calculate advance with kerning let advance = glyph.xadvance * fontScale; // Add kerning if there's a previous character if (prevCodepoint !== 0) { const kerning = SdfFontHandler.getKerning(fontFamily, prevCodepoint, codepoint); advance += kerning * fontScale; } // Add letter spacing advance += letterSpacing; yield { mapped: true, codepoint, xAdvance: advance, }; prevCodepoint = codepoint; } }, }); //# sourceMappingURL=SimpleFontShaper.js.map