2 * Copyright 2007-2009, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Maxim Shemanarev <mcseemagg@yahoo.com>
7 * Stephan Aßmus <superstippi@gmx.de>
8 * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk>
11 //----------------------------------------------------------------------------
12 // Anti-Grain Geometry - Version 2.4
13 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
20 //----------------------------------------------------------------------------
21 // Contact: mcseem@antigrain.com
22 // mcseemagg@yahoo.com
23 // http://www.antigrain.com
24 //----------------------------------------------------------------------------
26 #ifndef FONT_CACHE_ENTRY_H
27 #define FONT_CACHE_ENTRY_H
32 #include <agg_conv_curve.h>
33 #include <agg_conv_contour.h>
34 #include <agg_conv_transform.h>
36 #include "ServerFont.h"
37 #include "FontEngine.h"
38 #include "MultiLocker.h"
39 #include "Referenceable.h"
40 #include "Transformable.h"
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
)
49 glyph_index(glyphIndex
),
50 data((uint8
*)malloc(dataSize
)),
56 precise_advance_x(preciseAdvanceX
),
57 precise_advance_y(preciseAdvanceY
),
58 inset_left(insetLeft
),
59 inset_right(insetRight
),
72 glyph_data_type data_type
;
76 float precise_advance_x
;
77 float precise_advance_y
;
81 GlyphCache
* hash_link
;
86 class FontCacheEntry
: public MultiLocker
, public BReferenceable
{
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
;
97 typedef agg::conv_transform
<CurveConverter
, Transformable
>
100 typedef agg::conv_transform
<ContourConverter
, Transformable
>
101 TransformedContourOutline
;
105 virtual ~FontCacheEntry();
107 bool Init(const ServerFont
& font
, bool forceVector
);
109 bool HasGlyphs(const char* utf8String
,
110 ssize_t glyphCount
) const;
112 const GlyphCache
* CachedGlyph(uint32 glyphCode
);
113 const GlyphCache
* CreateGlyph(uint32 glyphCode
,
114 FontCacheEntry
* fallbackEntry
= NULL
);
116 void InitAdaptors(const GlyphCache
* glyph
,
118 GlyphMonoAdapter
& monoAdapter
,
119 GlyphGray8Adapter
& gray8Adapter
,
120 GlyphPathAdapter
& pathAdapter
,
123 bool GetKerning(uint32 glyphCode1
,
124 uint32 glyphCode2
, double* x
, double* y
);
126 static void GenerateSignature(char* signature
,
127 size_t signatureSize
,
128 const ServerFont
& font
, bool forceVector
);
130 // private to FontCache class:
132 bigtime_t
LastUsed() const
133 { return fLastUsedTime
; }
134 uint64
UsedCount() const
135 { return fUseCounter
; }
138 FontCacheEntry(const FontCacheEntry
&);
139 const FontCacheEntry
& operator=(const FontCacheEntry
&);
141 static glyph_rendering
_RenderTypeFor(const ServerFont
& font
,
144 class GlyphCachePool
;
146 GlyphCachePool
* fGlyphCache
;
149 static BLocker sUsageUpdateLock
;
150 bigtime_t fLastUsedTime
;
154 #endif // FONT_CACHE_ENTRY_H