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) 24ac41b0f1SStefano Ceccherini * Description: _BWidthBuffer_ 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 31f1569dbbSStefano Ceccherini #include "TextViewSupportBuffer.h" 32f1569dbbSStefano Ceccherini 33*54c0657bSbeveloper class BFont; // forward declaration 34*54c0657bSbeveloper 35ac41b0f1SStefano Ceccherini // TODO: enable this as soon as we are sure opentracker works 36ac41b0f1SStefano Ceccherini // with our libraries, since using a BFont here (as Dano does) is much better, 37ac41b0f1SStefano Ceccherini // as fonts can be classified also by spacing mode and other attributes. 38ac41b0f1SStefano Ceccherini #define USE_DANO_WIDTHBUFFER 0 39ac41b0f1SStefano Ceccherini 40f1569dbbSStefano Ceccherini struct _width_table_ { 41ac41b0f1SStefano Ceccherini #if USE_DANO_WIDTHBUFFER 42f1569dbbSStefano Ceccherini BFont font; // corresponding font 43f1569dbbSStefano Ceccherini #else 44f1569dbbSStefano Ceccherini int32 fontCode; // font code 45f1569dbbSStefano Ceccherini float fontSize; // font size 46f1569dbbSStefano Ceccherini #endif 47f1569dbbSStefano Ceccherini int32 hashCount; // number of hashed items 48f1569dbbSStefano Ceccherini int32 tableCount; // size of table 49f1569dbbSStefano Ceccherini void *widths; // width table 50f1569dbbSStefano Ceccherini }; 51f1569dbbSStefano Ceccherini 52ac41b0f1SStefano Ceccherini 53e0649957SStefano Ceccherini class _BTextGapBuffer_; 54f1569dbbSStefano Ceccherini class _BWidthBuffer_ : public _BTextViewSupportBuffer_<_width_table_> { 55f1569dbbSStefano Ceccherini public: 56f1569dbbSStefano Ceccherini _BWidthBuffer_(); 57f1569dbbSStefano Ceccherini virtual ~_BWidthBuffer_(); 58f1569dbbSStefano Ceccherini 59f1569dbbSStefano Ceccherini float StringWidth(const char *inText, int32 fromOffset, int32 length, 60f1569dbbSStefano Ceccherini const BFont *inStyle); 61ac41b0f1SStefano Ceccherini float StringWidth(_BTextGapBuffer_ &gapBuffer, int32 fromOffset, int32 length, 62f1569dbbSStefano Ceccherini const BFont *inStyle); 63f1569dbbSStefano Ceccherini 64f1569dbbSStefano Ceccherini private: 65f1569dbbSStefano Ceccherini bool FindTable(const BFont *font, int32 *outIndex); 66f1569dbbSStefano Ceccherini int32 InsertTable(const BFont *font); 67f1569dbbSStefano Ceccherini 68ac41b0f1SStefano Ceccherini bool GetEscapement(uint32 value, int32 index, float *escapement); 69ac41b0f1SStefano Ceccherini float HashEscapements(const char *chars, int32 numChars, int32 numBytes, 70ac41b0f1SStefano Ceccherini int32 tableIndex, const BFont *font); 71f1569dbbSStefano Ceccherini 72f1569dbbSStefano Ceccherini static uint32 Hash(uint32); 73f1569dbbSStefano Ceccherini }; 74f1569dbbSStefano Ceccherini 75f1569dbbSStefano Ceccherini #endif // __WIDTHBUFFER_H 76