2004-04-09 15:07:35 +04:00
|
|
|
/*
|
2010-07-03 13:34:59 +04:00
|
|
|
* Copyright 2003-2010, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
2004-04-09 15:07:35 +04:00
|
|
|
*/
|
2004-01-15 10:15:37 +03:00
|
|
|
#ifndef __WIDTHBUFFER_H
|
|
|
|
#define __WIDTHBUFFER_H
|
|
|
|
|
2009-11-30 14:25:13 +03:00
|
|
|
|
|
|
|
#include <Locker.h>
|
2008-09-20 19:08:40 +04:00
|
|
|
#include <TextView.h>
|
|
|
|
|
2004-01-15 10:15:37 +03:00
|
|
|
#include "TextViewSupportBuffer.h"
|
|
|
|
|
2008-09-20 19:08:40 +04:00
|
|
|
|
|
|
|
class BFont;
|
|
|
|
|
2004-06-20 21:43:32 +04:00
|
|
|
|
2008-09-22 00:47:16 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2008-09-22 00:47:16 +04:00
|
|
|
class TextGapBuffer;
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2004-01-15 10:15:37 +03:00
|
|
|
struct _width_table_ {
|
|
|
|
BFont font; // corresponding font
|
|
|
|
int32 hashCount; // number of hashed items
|
|
|
|
int32 tableCount; // size of table
|
2010-07-03 13:34:59 +04:00
|
|
|
void* widths; // width table
|
2004-01-15 10:15:37 +03:00
|
|
|
};
|
|
|
|
|
2010-07-03 13:34:59 +04:00
|
|
|
|
2008-09-22 00:47:16 +04:00
|
|
|
class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
|
2004-01-15 10:15:37 +03:00
|
|
|
public:
|
2010-08-11 22:03:37 +04:00
|
|
|
WidthBuffer();
|
|
|
|
virtual ~WidthBuffer();
|
2004-01-15 10:15:37 +03:00
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
float StringWidth(const char* inText,
|
|
|
|
int32 fromOffset, int32 length,
|
|
|
|
const BFont* inStyle);
|
|
|
|
float StringWidth(TextGapBuffer& gapBuffer,
|
|
|
|
int32 fromOffset, int32 length,
|
|
|
|
const BFont* inStyle);
|
2004-01-15 10:15:37 +03:00
|
|
|
|
|
|
|
private:
|
2010-08-11 22:03:37 +04:00
|
|
|
bool FindTable(const BFont* font, int32* outIndex);
|
|
|
|
int32 InsertTable(const BFont* font);
|
2009-11-30 14:25:13 +03:00
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
bool GetEscapement(uint32 value, int32 index,
|
|
|
|
float* escapement);
|
|
|
|
float HashEscapements(const char* chars,
|
|
|
|
int32 numChars, int32 numBytes,
|
|
|
|
int32 tableIndex, const BFont* font);
|
2009-11-30 14:25:13 +03:00
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
static uint32 Hash(uint32);
|
2009-11-30 14:25:13 +03:00
|
|
|
|
|
|
|
private:
|
2010-08-11 22:03:37 +04:00
|
|
|
BLocker fLock;
|
2004-01-15 10:15:37 +03:00
|
|
|
};
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2008-11-06 14:31:40 +03:00
|
|
|
extern WidthBuffer* gWidthBuffer;
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2008-09-22 00:47:16 +04:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2008-11-06 14:31:40 +03:00
|
|
|
using BPrivate::WidthBuffer;
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2008-11-06 14:31:40 +03:00
|
|
|
#if __GNUC__ < 3
|
|
|
|
//! NetPositive binary compatibility support
|
|
|
|
|
|
|
|
class _BWidthBuffer_ : public _BTextViewSupportBuffer_<BPrivate::_width_table_> {
|
|
|
|
_BWidthBuffer_();
|
|
|
|
virtual ~_BWidthBuffer_();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern
|
|
|
|
_BWidthBuffer_* gCompatibilityWidthBuffer;
|
|
|
|
|
|
|
|
#endif // __GNUC__ < 3
|
|
|
|
|
2010-08-11 22:03:37 +04:00
|
|
|
|
2004-01-15 10:15:37 +03:00
|
|
|
#endif // __WIDTHBUFFER_H
|