[haiku-commits] r37369 - in haiku/trunk: headers/private/interface src/kits/interface/textview_support

  • From: stefano.ceccherini@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 3 Jul 2010 11:34:59 +0200 (CEST)

Author: jackburton
Date: 2010-07-03 11:34:59 +0200 (Sat, 03 Jul 2010)
New Revision: 37369
Changeset: http://dev.haiku-os.org/changeset/37369/haiku

Modified:
   haiku/trunk/headers/private/interface/TextViewSupportBuffer.h
   haiku/trunk/headers/private/interface/WidthBuffer.h
   haiku/trunk/src/kits/interface/textview_support/WidthBuffer.cpp
Log:
Use the Bfont object to discriminate between fonts (as in Dano)
and not just size and code. Style cleanups.


Modified: haiku/trunk/headers/private/interface/TextViewSupportBuffer.h
===================================================================
--- haiku/trunk/headers/private/interface/TextViewSupportBuffer.h       
2010-07-03 09:16:17 UTC (rev 37368)
+++ haiku/trunk/headers/private/interface/TextViewSupportBuffer.h       
2010-07-03 09:34:59 UTC (rev 37369)
@@ -1,30 +1,7 @@
-//------------------------------------------------------------------------------
-//     Copyright (c) 2001-2004, Haiku, Inc.
-//
-//     Permission is hereby granted, free of charge, to any person obtaining a
-//     copy of this software and associated documentation files (the 
"Software"),
-//     to deal in the Software without restriction, including without 
limitation
-//     the rights to use, copy, modify, merge, publish, distribute, sublicense,
-//     and/or sell copies of the Software, and to permit persons to whom the
-//     Software is furnished to do so, subject to the following conditions:
-//
-//     The above copyright notice and this permission notice shall be included 
in
-//     all copies or substantial portions of the Software.
-//
-//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
OR
-//     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-//     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE
-//     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-//     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-//     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-//     DEALINGS IN THE SOFTWARE.
-//
-//     File Name:              TextViewSupportBuffer.h
-//     Authors                 Marc Flerackers (mflerackers@xxxxxxxxxx)
-//                                     Stefano Ceccherini (burton666@xxxxxxxxx)
-//     Description:    Template class used to implement the various BTextView
-//                                     buffer classes.
-//------------------------------------------------------------------------------
+/*
+ * Copyright 2001-2010, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
 
 #ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__
 #define __TEXT_VIEW_SUPPORT_BUFFER__H__
@@ -44,7 +21,7 @@
                                _BTextViewSupportBuffer_(int32 inExtraCount = 
0, int32 inCount = 0);
 virtual                        ~_BTextViewSupportBuffer_();
 
-               void    InsertItemsAt(int32 inNumItems, int32 inAtIndex, const 
T *inItem);
+               void    InsertItemsAt(int32 inNumItems, int32 inAtIndex, const 
T* inItem);
                void    RemoveItemsAt(int32 inNumItems, int32 inAtIndex);
 
                int32   ItemCount() const;
@@ -65,7 +42,7 @@
                fBufferCount(fExtraCount + fItemCount),
                fBuffer(NULL)
 {
-       fBuffer = (T *)calloc(fExtraCount + fItemCount, sizeof(T));
+       fBuffer = (T*)calloc(fExtraCount + fItemCount, sizeof(T));
 }
 
 
@@ -80,7 +57,7 @@
 void
 _BTextViewSupportBuffer_<T>::InsertItemsAt(int32 inNumItems,
                                                                                
                int32 inAtIndex,
-                                                                               
                const T *inItem)
+                                                                               
                const T* inItem)
 {
        if (inNumItems < 1)
                return;
@@ -92,12 +69,12 @@
        int32 logSize = fItemCount * sizeof(T);
        if ((logSize + delta) >= fBufferCount) {
                fBufferCount = logSize + delta + (fExtraCount * sizeof(T));
-               fBuffer = (T *)realloc(fBuffer, fBufferCount);
+               fBuffer = (T*)realloc(fBuffer, fBufferCount);
                if (fBuffer == NULL)
                        debugger("InsertItemsAt(): reallocation failed");
        }
        
-       T *loc = fBuffer + inAtIndex;
+       T* loc = fBuffer + inAtIndex;
        memmove(loc + inNumItems, loc, (fItemCount - inAtIndex) * sizeof(T));
        memcpy(loc, inItem, delta);
        
@@ -116,7 +93,7 @@
        inAtIndex = (inAtIndex > fItemCount - 1) ? (fItemCount - 1) : inAtIndex;
        inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
        
-       T *loc = fBuffer + inAtIndex;
+       T* loc = fBuffer + inAtIndex;
        memmove(loc, loc + inNumItems, 
                        (fItemCount - (inNumItems + inAtIndex)) * sizeof(T));
        
@@ -125,7 +102,7 @@
        uint32 extraSize = fBufferCount - (logSize - delta);
        if (extraSize > (fExtraCount * sizeof(T))) {
                fBufferCount = (logSize - delta) + (fExtraCount * sizeof(T));
-               fBuffer = (T *)realloc(fBuffer, fBufferCount);
+               fBuffer = (T*)realloc(fBuffer, fBufferCount);
                if (fBuffer == NULL)
                        debugger("RemoveItemsAt(): reallocation failed");
        }

Modified: haiku/trunk/headers/private/interface/WidthBuffer.h
===================================================================
--- haiku/trunk/headers/private/interface/WidthBuffer.h 2010-07-03 09:16:17 UTC 
(rev 37368)
+++ haiku/trunk/headers/private/interface/WidthBuffer.h 2010-07-03 09:34:59 UTC 
(rev 37369)
@@ -1,29 +1,6 @@
 /*
- * Copyright (c) 2003-2004 OpenBeOS
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * File:               WidthBuffer.cpp
- * Author:             Stefano Ceccherini (burton666@xxxxxxxxx)
- * Description: WidthBuffer stores charachters widths in a hash table, to be 
able
- *                             to retrieve them without passing through the 
app server.
- *                             Used by BTextView and OpenTracker.
+ * Copyright 2003-2010, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
  */
 #ifndef __WIDTHBUFFER_H
 #define __WIDTHBUFFER_H
@@ -38,44 +15,35 @@
 class BFont;
 
 
-// TODO: enable this as soon as we are sure opentracker works
-// with our libraries, since using a BFont here (as Dano does) is much better,
-// as fonts can be classified also by spacing mode and other attributes.
-#define USE_DANO_WIDTHBUFFER 0
-
 namespace BPrivate {
 
 class TextGapBuffer;
 
 struct _width_table_ {
-#if USE_DANO_WIDTHBUFFER
        BFont font;                             // corresponding font
-#else
-       int32 fontCode;                 // font code
-       float fontSize;                 // font size
-#endif
        int32 hashCount;                // number of hashed items
        int32 tableCount;               // size of table
-       void *widths;                   // width table
+       void* widths;                   // width table
 };
 
+
 class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
 public:
        WidthBuffer();
        virtual ~WidthBuffer();
 
-       float StringWidth(const char *inText, int32 fromOffset, int32 length,
-               const BFont *inStyle);
-       float StringWidth(TextGapBuffer &gapBuffer, int32 fromOffset,
-               int32 length, const BFont *inStyle);
+       float StringWidth(const char* inText, int32 fromOffset, int32 length,
+               const BFont* inStyle);
+       float StringWidth(TextGapBuffer& gapBuffer, int32 fromOffset,
+               int32 length, const BFont* inStyle);
 
 private:
-       bool FindTable(const BFont *font, int32 *outIndex);
-       int32 InsertTable(const BFont *font);
+       bool FindTable(const BFont* font, int32* outIndex);
+       int32 InsertTable(const BFont* font);
 
-       bool GetEscapement(uint32 value, int32 index, float *escapement);
-       float HashEscapements(const char *chars, int32 numChars, int32 numBytes,
-               int32 tableIndex, const BFont *font);
+       bool GetEscapement(uint32 value, int32 index, float* escapement);
+       float HashEscapements(const char* chars, int32 numChars, int32 numBytes,
+               int32 tableIndex, const BFont* font);
 
        static uint32 Hash(uint32);
 

Modified: haiku/trunk/src/kits/interface/textview_support/WidthBuffer.cpp
===================================================================
--- haiku/trunk/src/kits/interface/textview_support/WidthBuffer.cpp     
2010-07-03 09:16:17 UTC (rev 37368)
+++ haiku/trunk/src/kits/interface/textview_support/WidthBuffer.cpp     
2010-07-03 09:34:59 UTC (rev 37369)
@@ -175,19 +175,10 @@
        if (inStyle == NULL)
                return false;
 
-       float fontSize = inStyle->Size();
-       int32 fontCode = inStyle->FamilyAndStyle();
        int32 tableIndex = -1;
 
        for (int32 i = 0; i < fItemCount; i++) {
-
-#if USE_DANO_WIDTHBUFFER
-               if (*inStyle == fBuffer[i].font)
-#else
-               if (fontSize == fBuffer[i].fontSize
-                       && fontCode == fBuffer[i].fontCode)
-#endif
-               {
+               if (*inStyle == fBuffer[i].font) {
                        tableIndex = i;
                        break;
                }
@@ -208,13 +199,7 @@
 {
        _width_table_ table;
 
-#if USE_DANO_WIDTHBUFFER
        table.font = *font;
-#else
-       table.fontSize = font->Size();
-       table.fontCode = font->FamilyAndStyle();
-#endif
-
        table.hashCount = 0;
        table.tableCount = kTableCount;
        table.widths = new hashed_escapement[kTableCount];


Other related posts:

  • » [haiku-commits] r37369 - in haiku/trunk: headers/private/interface src/kits/interface/textview_support - stefano . ceccherini