vfs: check userland buffers before reading them.
[haiku.git] / headers / private / interface / WidthBuffer.h
blob266d7b53d4fbeb7d41ac51c7a2aa679d83e673e2
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
9 #include <Locker.h>
10 #include <TextView.h>
12 #include "TextViewSupportBuffer.h"
15 class BFont;
18 namespace BPrivate {
21 class TextGapBuffer;
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
32 class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
33 public:
34 WidthBuffer();
35 virtual ~WidthBuffer();
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);
44 private:
45 bool FindTable(const BFont* font, int32* outIndex);
46 int32 InsertTable(const BFont* font);
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);
54 static uint32 Hash(uint32);
56 private:
57 BLocker fLock;
61 extern WidthBuffer* gWidthBuffer;
64 } // namespace BPrivate
67 using BPrivate::WidthBuffer;
70 #if __GNUC__ < 3
71 //! NetPositive binary compatibility support
73 class _BWidthBuffer_ : public _BTextViewSupportBuffer_<BPrivate::_width_table_> {
74 _BWidthBuffer_();
75 virtual ~_BWidthBuffer_();
78 extern
79 _BWidthBuffer_* gCompatibilityWidthBuffer;
81 #endif // __GNUC__ < 3
84 #endif // __WIDTHBUFFER_H