xref: /haiku/headers/private/interface/WidthBuffer.h (revision 22440f4105cafc95cc1d49f9bc65bb395c527d86)
1 /*
2  * Copyright 2003-2010, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef __WIDTHBUFFER_H
6 #define __WIDTHBUFFER_H
7 
8 
9 #include <Locker.h>
10 #include <TextView.h>
11 
12 #include "TextViewSupportBuffer.h"
13 
14 
15 class BFont;
16 
17 
18 namespace BPrivate {
19 
20 
21 class TextGapBuffer;
22 
23 
24 struct _width_table_ {
25 	BFont font;				// corresponding font
26 	int32 hashCount;		// number of hashed items
27 	int32 tableCount;		// size of table
28 	void* widths;			// width table
29 };
30 
31 
32 class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
33 public:
34 								WidthBuffer();
35 	virtual						~WidthBuffer();
36 
37 			float				StringWidth(const char* inText,
38 									int32 fromOffset, int32 length,
39 									const BFont* inStyle);
40 			float				StringWidth(TextGapBuffer& gapBuffer,
41 									int32 fromOffset, int32 length,
42 									const BFont* inStyle);
43 
44 private:
45 			bool				FindTable(const BFont* font, int32* outIndex);
46 			int32				InsertTable(const BFont* font);
47 
48 			bool				GetEscapement(uint32 value, int32 index,
49 									float* escapement);
50 			float				HashEscapements(const char* chars,
51 									int32 numChars, int32 numBytes,
52 									int32 tableIndex, const BFont* font);
53 
54 	static	uint32				Hash(uint32);
55 
56 private:
57 			BLocker				fLock;
58 };
59 
60 
61 extern WidthBuffer* gWidthBuffer;
62 
63 
64 } // namespace BPrivate
65 
66 
67 using BPrivate::WidthBuffer;
68 
69 
70 #if __GNUC__ < 3
71 //! NetPositive binary compatibility support
72 
73 class _BWidthBuffer_ : public _BTextViewSupportBuffer_<BPrivate::_width_table_> {
74 	_BWidthBuffer_();
75 	virtual ~_BWidthBuffer_();
76 };
77 
78 extern
79 _BWidthBuffer_* gCompatibilityWidthBuffer;
80 
81 #endif // __GNUC__ < 3
82 
83 
84 #endif // __WIDTHBUFFER_H
85