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