/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "Shelf.hpp" #include "Extensions/FreetypeHelper.hpp" namespace OpenVulkano::Scene { std::vector Shelf::CreateShelves(uint32_t atlasWidth, std::vector& glyphs, FT_FaceRec_* face, int channelsCount) { std::vector shelves; for (GlyphForPacking& glyph : glyphs) { FT_Error error = FT_Load_Char(face, glyph.code, FT_LOAD_RENDER); if (error) continue; bool needNewShelf = true; uint32_t totalPrevShelvesHeight = 0; for (Shelf& shelf : shelves) { if (std::optional> opt = shelf.AddGlyph(glyph.size.x, glyph.size.y)) { glyph.firstGlyphByteInAtlas = opt->second; glyph.atlasPos.x = opt->first; glyph.atlasPos.y = totalPrevShelvesHeight; needNewShelf = false; break; } totalPrevShelvesHeight += shelf.GetHeight(); } if (needNewShelf) { shelves.emplace_back(atlasWidth, glyph.size.y, channelsCount, totalPrevShelvesHeight); Shelf& shelf = shelves.back(); uint32_t firstByte = (*shelf.AddGlyph(glyph.size.x, glyph.size.y)).second; glyph.firstGlyphByteInAtlas = firstByte; glyph.atlasPos.x = 0; glyph.atlasPos.y = totalPrevShelvesHeight; } } return shelves; } }