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
15class BFont;
16
17
18namespace BPrivate {
19
20
21class TextGapBuffer;
22
23
24struct _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
32class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
33public:
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
44private:
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
56private:
57			BLocker				fLock;
58};
59
60
61extern WidthBuffer* gWidthBuffer;
62
63
64} // namespace BPrivate
65
66
67using BPrivate::WidthBuffer;
68
69
70#if __GNUC__ < 3
71//! NetPositive binary compatibility support
72
73class _BWidthBuffer_ : public _BTextViewSupportBuffer_<BPrivate::_width_table_> {
74	_BWidthBuffer_();
75	virtual ~_BWidthBuffer_();
76};
77
78extern
79_BWidthBuffer_* gCompatibilityWidthBuffer;
80
81#endif // __GNUC__ < 3
82
83
84#endif // __WIDTHBUFFER_H
85