1 /* 2 * Copyright 2007-2009, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Maxim Shemanarev <mcseemagg@yahoo.com> 7 * Stephan Aßmus <superstippi@gmx.de> 8 * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 9 */ 10 11 //---------------------------------------------------------------------------- 12 // Anti-Grain Geometry - Version 2.4 13 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 14 // 15 // Permission to copy, use, modify, sell and distribute this software 16 // is granted provided this copyright notice appears in all copies. 17 // This software is provided "as is" without express or implied 18 // warranty, and with no claim as to its suitability for any purpose. 19 // 20 //---------------------------------------------------------------------------- 21 // Contact: mcseem@antigrain.com 22 // mcseemagg@yahoo.com 23 // http://www.antigrain.com 24 //---------------------------------------------------------------------------- 25 26 #ifndef FONT_CACHE_ENTRY_H 27 #define FONT_CACHE_ENTRY_H 28 29 30 #include <Locker.h> 31 32 #include <agg_conv_curve.h> 33 #include <agg_conv_contour.h> 34 #include <agg_conv_transform.h> 35 36 #include "ServerFont.h" 37 #include "FontEngine.h" 38 #include "MultiLocker.h" 39 #include "Referenceable.h" 40 #include "Transformable.h" 41 42 43 struct GlyphCache { 44 GlyphCache(uint32 glyphIndex, uint32 dataSize, glyph_data_type dataType, 45 const agg::rect_i& bounds, float advanceX, float advanceY, 46 float preciseAdvanceX, float preciseAdvanceY, 47 float insetLeft, float insetRight) 48 : 49 glyph_index(glyphIndex), 50 data((uint8*)malloc(dataSize)), 51 data_size(dataSize), 52 data_type(dataType), 53 bounds(bounds), 54 advance_x(advanceX), 55 advance_y(advanceY), 56 precise_advance_x(preciseAdvanceX), 57 precise_advance_y(preciseAdvanceY), 58 inset_left(insetLeft), 59 inset_right(insetRight), 60 hash_link(NULL) 61 { 62 } 63 64 ~GlyphCache() 65 { 66 free(data); 67 } 68 69 uint32 glyph_index; 70 uint8* data; 71 uint32 data_size; 72 glyph_data_type data_type; 73 agg::rect_i bounds; 74 float advance_x; 75 float advance_y; 76 float precise_advance_x; 77 float precise_advance_y; 78 float inset_left; 79 float inset_right; 80 81 GlyphCache* hash_link; 82 }; 83 84 class FontCache; 85 86 class FontCacheEntry : public MultiLocker, public BReferenceable { 87 public: 88 typedef FontEngine::PathAdapter GlyphPathAdapter; 89 typedef FontEngine::Gray8Adapter GlyphGray8Adapter; 90 typedef GlyphGray8Adapter::embedded_scanline GlyphGray8Scanline; 91 typedef FontEngine::MonoAdapter GlyphMonoAdapter; 92 typedef GlyphMonoAdapter::embedded_scanline GlyphMonoScanline; 93 typedef FontEngine::SubpixAdapter SubpixAdapter; 94 typedef agg::conv_curve<GlyphPathAdapter> CurveConverter; 95 typedef agg::conv_contour<CurveConverter> ContourConverter; 96 97 typedef agg::conv_transform<CurveConverter, Transformable> 98 TransformedOutline; 99 100 typedef agg::conv_transform<ContourConverter, Transformable> 101 TransformedContourOutline; 102 103 104 FontCacheEntry(); 105 virtual ~FontCacheEntry(); 106 107 bool Init(const ServerFont& font, bool forceVector); 108 109 bool HasGlyphs(const char* utf8String, 110 ssize_t glyphCount) const; 111 112 const GlyphCache* CachedGlyph(uint32 glyphCode); 113 const GlyphCache* CreateGlyph(uint32 glyphCode, 114 FontCacheEntry* fallbackEntry = NULL); 115 116 void InitAdaptors(const GlyphCache* glyph, 117 double x, double y, 118 GlyphMonoAdapter& monoAdapter, 119 GlyphGray8Adapter& gray8Adapter, 120 GlyphPathAdapter& pathAdapter, 121 double scale = 1.0); 122 123 bool GetKerning(uint32 glyphCode1, 124 uint32 glyphCode2, double* x, double* y); 125 126 static void GenerateSignature(char* signature, 127 size_t signatureSize, 128 const ServerFont& font, bool forceVector); 129 130 // private to FontCache class: 131 void UpdateUsage(); 132 bigtime_t LastUsed() const 133 { return fLastUsedTime; } 134 uint64 UsedCount() const 135 { return fUseCounter; } 136 137 private: 138 FontCacheEntry(const FontCacheEntry&); 139 const FontCacheEntry& operator=(const FontCacheEntry&); 140 141 static glyph_rendering _RenderTypeFor(const ServerFont& font, 142 bool forceVector); 143 144 class GlyphCachePool; 145 146 GlyphCachePool* fGlyphCache; 147 FontEngine fEngine; 148 149 static BLocker sUsageUpdateLock; 150 bigtime_t fLastUsedTime; 151 uint64 fUseCounter; 152 }; 153 154 #endif // FONT_CACHE_ENTRY_H 155 156