Use the Bfont object to discriminate between fonts (as in Dano)

and not just size and code. Style cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37369 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2010-07-03 09:34:59 +00:00
parent 6b176bef5b
commit 4225e5b785
3 changed files with 25 additions and 95 deletions
@@ -1,30 +1,7 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2004, Haiku, Inc. * Copyright 2001-2010, Haiku, Inc.
// * Distributed under the terms of the MIT License.
// 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 ([email protected])
// Stefano Ceccherini ([email protected])
// Description: Template class used to implement the various BTextView
// buffer classes.
//------------------------------------------------------------------------------
#ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__ #ifndef __TEXT_VIEW_SUPPORT_BUFFER__H__
#define __TEXT_VIEW_SUPPORT_BUFFER__H__ #define __TEXT_VIEW_SUPPORT_BUFFER__H__
+3 -35
View File
@@ -1,29 +1,6 @@
/* /*
* Copyright (c) 2003-2004 OpenBeOS * Copyright 2003-2010, Haiku, Inc.
* * Distributed under the terms of the MIT License.
* 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 ([email protected])
* 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.
*/ */
#ifndef __WIDTHBUFFER_H #ifndef __WIDTHBUFFER_H
#define __WIDTHBUFFER_H #define __WIDTHBUFFER_H
@@ -38,27 +15,18 @@
class BFont; 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 { namespace BPrivate {
class TextGapBuffer; class TextGapBuffer;
struct _width_table_ { struct _width_table_ {
#if USE_DANO_WIDTHBUFFER
BFont font; // corresponding font BFont font; // corresponding font
#else
int32 fontCode; // font code
float fontSize; // font size
#endif
int32 hashCount; // number of hashed items int32 hashCount; // number of hashed items
int32 tableCount; // size of table int32 tableCount; // size of table
void* widths; // width table void* widths; // width table
}; };
class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> { class WidthBuffer : public _BTextViewSupportBuffer_<_width_table_> {
public: public:
WidthBuffer(); WidthBuffer();
@@ -175,19 +175,10 @@ WidthBuffer::FindTable(const BFont *inStyle, int32 *outIndex)
if (inStyle == NULL) if (inStyle == NULL)
return false; return false;
float fontSize = inStyle->Size();
int32 fontCode = inStyle->FamilyAndStyle();
int32 tableIndex = -1; int32 tableIndex = -1;
for (int32 i = 0; i < fItemCount; i++) { for (int32 i = 0; i < fItemCount; i++) {
if (*inStyle == fBuffer[i].font) {
#if USE_DANO_WIDTHBUFFER
if (*inStyle == fBuffer[i].font)
#else
if (fontSize == fBuffer[i].fontSize
&& fontCode == fBuffer[i].fontCode)
#endif
{
tableIndex = i; tableIndex = i;
break; break;
} }
@@ -208,13 +199,7 @@ WidthBuffer::InsertTable(const BFont *font)
{ {
_width_table_ table; _width_table_ table;
#if USE_DANO_WIDTHBUFFER
table.font = *font; table.font = *font;
#else
table.fontSize = font->Size();
table.fontCode = font->FamilyAndStyle();
#endif
table.hashCount = 0; table.hashCount = 0;
table.tableCount = kTableCount; table.tableCount = kTableCount;
table.widths = new hashed_escapement[kTableCount]; table.widths = new hashed_escapement[kTableCount];