1 /** 2 * Copyright (c) 2006-2019 LOVE Development Team 3 * 4 * This software is provided 'as-is', without any express or implied 5 * warranty. In no event will the authors be held liable for any damages 6 * arising from the use of this software. 7 * 8 * Permission is granted to anyone to use this software for any purpose, 9 * including commercial applications, and to alter it and redistribute it 10 * freely, subject to the following restrictions: 11 * 12 * 1. The origin of this software must not be misrepresented; you must not 13 * claim that you wrote the original software. If you use this software 14 * in a product, an acknowledgment in the product documentation would be 15 * appreciated but is not required. 16 * 2. Altered source versions must be plainly marked as such, and must not be 17 * misrepresented as being the original software. 18 * 3. This notice may not be removed or altered from any source distribution. 19 **/ 20 21 #ifndef LOVE_FONT_IMAGE_RASTERIZER_H 22 #define LOVE_FONT_IMAGE_RASTERIZER_H 23 24 // LOVE 25 #include "font/Rasterizer.h" 26 #include "image/ImageData.h" 27 #include "common/Color.h" 28 29 #include <map> 30 31 namespace love 32 { 33 namespace font 34 { 35 36 /** 37 * Holds data for a font object. 38 **/ 39 class ImageRasterizer : public Rasterizer 40 { 41 public: 42 ImageRasterizer(love::image::ImageData *imageData, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale); 43 virtual ~ImageRasterizer(); 44 45 // Implement Rasterizer 46 int getLineHeight() const override; 47 GlyphData *getGlyphData(uint32 glyph) const override; 48 int getGlyphCount() const override; 49 bool hasGlyph(uint32 glyph) const override; 50 DataType getDataType() const override; 51 52 53 private: 54 55 // Information about a glyph in the ImageData 56 struct ImageGlyphData 57 { 58 int x; 59 int width; 60 }; 61 62 // Load all the glyph positions into memory 63 void load(); 64 65 // The image data 66 StrongRef<love::image::ImageData> imageData; 67 68 // The glyphs in the font 69 uint32 *glyphs; 70 71 // Number of glyphs in the font 72 int numglyphs; 73 74 int extraSpacing; 75 76 std::map<uint32, ImageGlyphData> imageGlyphs; 77 78 // Color used to identify glyph separation in the source ImageData 79 Color32 spacer; 80 81 }; // ImageRasterizer 82 83 } // font 84 } // love 85 86 #endif // LOVE_FONT_IMAGE_RASTERIZER_H 87