xref: /haiku/headers/private/interface/WidthBuffer.h (revision 90b7764dc354ff1bcb01abf78dafe16faa820725)
1ac41b0f1SStefano Ceccherini /*
2ac41b0f1SStefano Ceccherini  * Copyright (c) 2003-2004 OpenBeOS
3ac41b0f1SStefano Ceccherini  *
4ac41b0f1SStefano Ceccherini  * Permission is hereby granted, free of charge, to any person obtaining a
5ac41b0f1SStefano Ceccherini  * copy of this software and associated documentation files (the "Software"),
6ac41b0f1SStefano Ceccherini  * to deal in the Software without restriction, including without limitation
7ac41b0f1SStefano Ceccherini  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ac41b0f1SStefano Ceccherini  * and/or sell copies of the Software, and to permit persons to whom the
9ac41b0f1SStefano Ceccherini  * Software is furnished to do so, subject to the following conditions:
10ac41b0f1SStefano Ceccherini  *
11ac41b0f1SStefano Ceccherini  * The above copyright notice and this permission notice shall be included in
12ac41b0f1SStefano Ceccherini  * all copies or substantial portions of the Software.
13ac41b0f1SStefano Ceccherini  *
14ac41b0f1SStefano Ceccherini  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ac41b0f1SStefano Ceccherini  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ac41b0f1SStefano Ceccherini  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17ac41b0f1SStefano Ceccherini  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18ac41b0f1SStefano Ceccherini  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19ac41b0f1SStefano Ceccherini  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20ac41b0f1SStefano Ceccherini  * DEALINGS IN THE SOFTWARE.
21ac41b0f1SStefano Ceccherini  *
22ac41b0f1SStefano Ceccherini  * File:		WidthBuffer.cpp
23ac41b0f1SStefano Ceccherini  * Author:		Stefano Ceccherini (burton666@libero.it)
24a682d981SStephan Aßmus  * Description: WidthBuffer stores charachters widths in a hash table, to be able
25ac41b0f1SStefano Ceccherini  *				to retrieve them without passing through the app server.
26ac41b0f1SStefano Ceccherini  *				Used by BTextView and OpenTracker.
27ac41b0f1SStefano Ceccherini  */
28f1569dbbSStefano Ceccherini #ifndef __WIDTHBUFFER_H
29f1569dbbSStefano Ceccherini #define __WIDTHBUFFER_H
30f1569dbbSStefano Ceccherini 
31a682d981SStephan Aßmus #include <TextView.h>
32a682d981SStephan Aßmus 
33f1569dbbSStefano Ceccherini #include "TextViewSupportBuffer.h"
34f1569dbbSStefano Ceccherini 
35a682d981SStephan Aßmus 
36a682d981SStephan Aßmus class BFont;
37a682d981SStephan Aßmus 
3854c0657bSbeveloper 
39ac41b0f1SStefano Ceccherini // TODO: enable this as soon as we are sure opentracker works
40ac41b0f1SStefano Ceccherini // with our libraries, since using a BFont here (as Dano does) is much better,
41ac41b0f1SStefano Ceccherini // as fonts can be classified also by spacing mode and other attributes.
42ac41b0f1SStefano Ceccherini #define USE_DANO_WIDTHBUFFER 0
43ac41b0f1SStefano Ceccherini 
44*90b7764dSRene Gollent namespace BPrivate {
45*90b7764dSRene Gollent 
46*90b7764dSRene Gollent class TextGapBuffer;
47*90b7764dSRene Gollent 
48f1569dbbSStefano Ceccherini struct _width_table_ {
49ac41b0f1SStefano Ceccherini #if USE_DANO_WIDTHBUFFER
50f1569dbbSStefano Ceccherini 	BFont font;				// corresponding font
51f1569dbbSStefano Ceccherini #else
52f1569dbbSStefano Ceccherini 	int32 fontCode;			// font code
53f1569dbbSStefano Ceccherini 	float fontSize;			// font size
54f1569dbbSStefano Ceccherini #endif
55f1569dbbSStefano Ceccherini 	int32 hashCount;		// number of hashed items
56f1569dbbSStefano Ceccherini 	int32 tableCount;		// size of table
57f1569dbbSStefano Ceccherini 	void *widths;			// width table
58f1569dbbSStefano Ceccherini };
59f1569dbbSStefano Ceccherini 
60*90b7764dSRene Gollent class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
61f1569dbbSStefano Ceccherini public:
62a682d981SStephan Aßmus 	WidthBuffer();
63a682d981SStephan Aßmus 	virtual ~WidthBuffer();
64f1569dbbSStefano Ceccherini 
65f1569dbbSStefano Ceccherini 	float StringWidth(const char *inText, int32 fromOffset, int32 length,
66f1569dbbSStefano Ceccherini 		const BFont *inStyle);
67*90b7764dSRene Gollent 	float StringWidth(TextGapBuffer &gapBuffer, int32 fromOffset,
68a682d981SStephan Aßmus 		int32 length, const BFont *inStyle);
69f1569dbbSStefano Ceccherini 
70f1569dbbSStefano Ceccherini private:
71f1569dbbSStefano Ceccherini 	bool FindTable(const BFont *font, int32 *outIndex);
72f1569dbbSStefano Ceccherini 	int32 InsertTable(const BFont *font);
73f1569dbbSStefano Ceccherini 
74ac41b0f1SStefano Ceccherini 	bool GetEscapement(uint32 value, int32 index, float *escapement);
75ac41b0f1SStefano Ceccherini 	float HashEscapements(const char *chars, int32 numChars, int32 numBytes,
76ac41b0f1SStefano Ceccherini 		int32 tableIndex, const BFont *font);
77f1569dbbSStefano Ceccherini 
78f1569dbbSStefano Ceccherini 	static uint32 Hash(uint32);
79f1569dbbSStefano Ceccherini };
80f1569dbbSStefano Ceccherini 
81*90b7764dSRene Gollent } // namespace BPrivate
82*90b7764dSRene Gollent 
83f1569dbbSStefano Ceccherini #endif // __WIDTHBUFFER_H
84