* A ServerFont is now always valid, bye-bye ServerFont::InitCheck().

* The FontFamily is no longer reference counting itself.
* SharedObject is now more useful and destructs itself when unused.
* Fixed FontStyle::GetHeight()/ServerFont::GetHeight() semantics.
* Simplified ServerFont constructors.
* Removed wrong function descriptions.
* FontStyleHeight is no longer used: the FontStyle is calculating the
  base font height on construction - this reduces the resolution a bit,
  but it's hopefully not causing any troubles (doesn't look like it,
  at least).
* A FontStyle now removes itself from its family on destruction.
* More cleanup, removed unused stuff like FontStyleHeight.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14657 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-03 13:10:28 +00:00
parent 8000593677
commit 8365d9ecd2
10 changed files with 228 additions and 278 deletions
+24 -48
View File
@@ -38,27 +38,6 @@ enum font_format {
FONT_WINFONT,
};
/*
//! data structure used by the FreeType cache manager
typedef struct CachedFaceRec_
{
BString file_path;
int face_index;
} CachedFaceRec, *CachedFace;
*/
/*!
\brief Private structure to store font height values
Units provided by FT2 are in font units, so they are stored in the style as
such. Each value must be multiplied by the point size to determine size in pixels
*/
typedef struct {
FT_Short ascent;
FT_Short descent;
FT_Short leading;
FT_UShort units_per_em;
} FontStyleHeight;
/*!
\class FontStyle FontFamily.h
@@ -78,53 +57,54 @@ class FontStyle : public SharedObject, public BLocker {
\return true if fixed, false if not
*/
bool IsFixedWidth() const
{ return fFTFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; }
{ return fFreeTypeFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; }
/*!
\fn bool FontStyle::IsScalable(void)
\brief Determines whether the font can be scaled to any size
\return true if scalable, false if not
*/
bool IsScalable() const
{ return fFTFace->face_flags & FT_FACE_FLAG_SCALABLE; }
{ return fFreeTypeFace->face_flags & FT_FACE_FLAG_SCALABLE; }
/*!
\fn bool FontStyle::HasKerning(void)
\brief Determines whether the font has kerning information
\return true if kerning info is available, false if not
*/
bool HasKerning() const
{ return fFTFace->face_flags & FT_FACE_FLAG_KERNING; }
{ return fFreeTypeFace->face_flags & FT_FACE_FLAG_KERNING; }
/*!
\fn bool FontStyle::HasTuned(void)
\brief Determines whether the font contains strikes
\return true if it has strikes included, false if not
*/
bool HasTuned() const
{ return fFTFace->num_fixed_sizes > 0; }
{ return fFreeTypeFace->num_fixed_sizes > 0; }
/*!
\fn bool FontStyle::TunedCount(void)
\brief Returns the number of strikes the style contains
\return The number of strikes the style contains
*/
int32 TunedCount() const
{ return fFTFace->num_fixed_sizes; }
{ return fFreeTypeFace->num_fixed_sizes; }
/*!
\fn bool FontStyle::GlyphCount(void)
\brief Returns the number of glyphs in the style
\return The number of glyphs the style contains
*/
uint16 GlyphCount() const
{ return fFTFace->num_glyphs; }
{ return fFreeTypeFace->num_glyphs; }
/*!
\fn bool FontStyle::CharMapCount(void)
\brief Returns the number of character maps the style contains
\return The number of character maps the style contains
*/
uint16 CharMapCount() const
{ return fFTFace->num_charmaps; }
{ return fFreeTypeFace->num_charmaps; }
const char* Name() const;
const char* Name() const
{ return fName.String(); }
FontFamily* Family() const
{ return fFontFamily; }
{ return fFamily; }
uint16 ID() const
{ return fID; }
int32 Flags() const;
@@ -134,14 +114,16 @@ class FontStyle : public SharedObject, public BLocker {
uint16 PreservedFace(uint16) const;
const char* Path() const;
font_height GetHeight(const float& size) const;
void GetHeight(float size, font_height &heigth) const;
font_direction Direction() const
{ return B_FONT_LEFT_TO_RIGHT; }
font_file_format FileFormat() const
{ return B_TRUETYPE_WINDOWS; }
FT_Face GetFTFace() const
{ return fFTFace; }
FT_Face FreeTypeFace() const
{ return fFreeTypeFace; }
status_t UpdateFace(FT_Face face);
// TODO: Re-enable when I understand how the FT2 Cache system changed from
// 2.1.4 to 2.1.8
@@ -150,26 +132,20 @@ class FontStyle : public SharedObject, public BLocker {
private:
friend class FontFamily;
uint16 _TranslateStyleToFace(const char *name) const;
void _SetFontFamily(FontFamily* family)
{ fFontFamily = family; }
void _SetID(uint16 id)
{ fID = id; }
void _SetFontFamily(FontFamily* family, uint16 id);
private:
FT_Face fFTFace;
// CachedFace cachedface;
FontFamily* fFontFamily;
FT_Face fFreeTypeFace;
BString fName;
BString fPath;
FontFamily* fFamily;
uint16 fID;
BRect fBounds;
uint16 fID;
font_height fHeight;
uint16 fFace;
FontStyleHeight fHeight;
};
/*!
@@ -179,7 +155,7 @@ class FontStyle : public SharedObject, public BLocker {
FontFamily objects bring together many styles of the same face, such as
Arial Roman, Arial Italic, Arial Bold, etc.
*/
class FontFamily : public SharedObject {
class FontFamily {
public:
FontFamily(const char* name, uint16 id);
virtual ~FontFamily();
@@ -187,8 +163,8 @@ class FontFamily : public SharedObject {
const char* Name() const;
bool AddStyle(FontStyle* style);
void RemoveStyle(const char* style);
void RemoveStyle(FontStyle* style);
bool RemoveStyle(const char* style);
bool RemoveStyle(FontStyle* style);
FontStyle* GetStyle(const char* style) const;
FontStyle* GetStyleMatchingFace(uint16 face) const;
+7 -12
View File
@@ -3,13 +3,13 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <[email protected]>
* Jérôme Duval, [email protected]
* DarkWyrm <[email protected]>
* Jérôme Duval, [email protected]
*/
#ifndef SERVERFONT_H_
#define SERVERFONT_H_
#include <Font.h>
#include <Rect.h>
@@ -18,10 +18,11 @@
class BShape;
class BString;
class ServerFont {
public:
ServerFont();
ServerFont(FontStyle* style,
ServerFont(FontStyle& style,
float size = 12.0,
float fRotation = 0.0,
float fShear = 90.0,
@@ -30,13 +31,7 @@ class ServerFont {
ServerFont(const ServerFont& font);
virtual ~ServerFont();
// TODO: make more advanced...
status_t InitCheck() const
{ return fStyle ? B_OK : B_NO_INIT; }
ServerFont &operator=(const ServerFont& font);
font_direction Direction() const
{ return fDirection; }
@@ -145,10 +140,10 @@ class ServerFont {
void Unlock() const { fStyle->Unlock(); }
FT_Face GetFTFace() const
{ return fStyle->GetFTFace(); };
{ return fStyle->FreeTypeFace(); };
BRect BoundingBox();
void Height(font_height* fh) const;
void GetHeight(font_height& height) const;
void TruncateString(BString* inOut,
uint32 mode,
+40 -46
View File
@@ -1,37 +1,18 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, 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: SharedObject.h
// Author: DarkWyrm <[email protected]>
// Description: This class is used as a base class for other objects which
// must be shared. By using this, objects which depend on its
// existence can be somewhat sure that the shared object will
// not be deleted until nothing depends on it.
//
//------------------------------------------------------------------------------
#ifndef SHAREDOBJ_H_
#define SHAREDOBJ_H_
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <[email protected]>
* Axel Dörfler, [email protected]
*/
#ifndef SHARED_OBJECT_H
#define SHARED_OBJECT_H
#include <SupportDefs.h>
/*!
\class SharedObject SharedObject.h
\brief Base class for shared objects
@@ -41,21 +22,34 @@
needs it. How the dependency tracking is done largely depends on the child class.
*/
class SharedObject {
public:
SharedObject()
: fReferenceCount(0)
{}
virtual ~SharedObject()
{}
public:
SharedObject()
: fReferenceCount(1) {}
virtual ~SharedObject() {}
virtual void AddDependent()
{ fReferenceCount++; }
virtual void RemoveDependent()
{ fReferenceCount--; }
virtual bool HasDependents()
{ return (fReferenceCount > 0); }
private:
uint32 fReferenceCount;
inline void Acquire();
inline bool Release();
private:
int32 fReferenceCount;
};
#endif
inline void
SharedObject::Acquire()
{
atomic_add(&fReferenceCount, 1);
}
inline bool
SharedObject::Release()
{
if (atomic_add(&fReferenceCount, -1) == 1) {
delete this;
return true;
}
return false;
}
#endif /* SHARED_OBJECT_H */