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