2003-01-01 01:19:48 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2004-09-21 02:50:02 +04:00
|
|
|
// Copyright (c) 2001-2002, Haiku, Inc.
|
2003-01-01 01:19:48 +03:00
|
|
|
//
|
|
|
|
// 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: ServerFont.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: Shadow BFont class
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include "ServerFont.h"
|
2005-01-21 16:13:08 +03:00
|
|
|
#include "FontServer.h"
|
2003-01-01 01:19:48 +03:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Constructor
|
2003-01-20 02:04:58 +03:00
|
|
|
\param style Style object to which the ServerFont belongs
|
|
|
|
\param size Character size in points
|
|
|
|
\param rotation Rotation in degrees
|
|
|
|
\param shear Shear (slant) in degrees. 45 <= shear <= 135
|
|
|
|
\param flags Style flags as defined in <Font.h>
|
|
|
|
\param spacing String spacing flag as defined in <Font.h>
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
|
|
|
ServerFont::ServerFont(FontStyle *style, float size, float rotation, float shear,
|
|
|
|
uint16 flags, uint8 spacing)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
fStyle=style;
|
|
|
|
fSize=size;
|
2003-01-01 01:19:48 +03:00
|
|
|
frotation=rotation;
|
|
|
|
fshear=shear;
|
2005-01-21 16:13:08 +03:00
|
|
|
fFlags=flags;
|
|
|
|
fSpacing=spacing;
|
|
|
|
fDirection=B_FONT_LEFT_TO_RIGHT;
|
|
|
|
fFace=B_REGULAR_FACE;
|
|
|
|
fEncoding=B_UNICODE_UTF8;
|
|
|
|
fBounds.Set(0,0,0,0);
|
|
|
|
if(fStyle)
|
|
|
|
fStyle->AddDependent();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2003-10-05 21:51:13 +04:00
|
|
|
ServerFont::ServerFont(void)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
fStyle=NULL;
|
|
|
|
fSize=0.0;
|
2003-10-05 21:51:13 +04:00
|
|
|
frotation=0.0;
|
|
|
|
fshear=90.0;
|
2005-01-21 16:13:08 +03:00
|
|
|
fFlags=0;
|
|
|
|
fSpacing=B_STRING_SPACING;
|
|
|
|
fDirection=B_FONT_LEFT_TO_RIGHT;
|
|
|
|
fFace=B_REGULAR_FACE;
|
|
|
|
fEncoding=B_UNICODE_UTF8;
|
|
|
|
fBounds.Set(0,0,0,0);
|
2003-10-05 21:51:13 +04:00
|
|
|
}
|
|
|
|
|
2003-01-01 01:19:48 +03:00
|
|
|
/*!
|
|
|
|
\brief Copy Constructor
|
2003-01-20 02:04:58 +03:00
|
|
|
\param font ServerFont to copy
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
|
|
|
ServerFont::ServerFont(const ServerFont &font)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
fStyle=font.fStyle;
|
|
|
|
fSize=font.fSize;
|
2003-01-01 01:19:48 +03:00
|
|
|
frotation=font.frotation;
|
|
|
|
fshear=font.fshear;
|
2005-01-21 16:13:08 +03:00
|
|
|
fFlags=font.fFlags;
|
|
|
|
fSpacing=font.fSpacing;
|
|
|
|
fDirection=font.fDirection;
|
|
|
|
fFace=font.fFace;
|
|
|
|
fEncoding=font.fEncoding;
|
|
|
|
fBounds.Set(0,0,0,0);
|
|
|
|
if(fStyle)
|
|
|
|
fStyle->AddDependent();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2003-01-18 23:32:45 +03:00
|
|
|
\brief Removes itself as a dependency of its owning style.
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
|
|
|
ServerFont::~ServerFont(void)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
if(fStyle)
|
|
|
|
fStyle->RemoveDependent();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2003-09-15 23:09:13 +04:00
|
|
|
/*!
|
|
|
|
\brief Returns a copy of the specified font
|
|
|
|
\param The font to copy from.
|
|
|
|
\return A copy of the specified font
|
|
|
|
*/
|
|
|
|
ServerFont& ServerFont::operator=(const ServerFont& font){
|
2005-01-21 16:13:08 +03:00
|
|
|
fStyle = font.fStyle;
|
|
|
|
fSize = font.fSize;
|
2003-09-15 23:09:13 +04:00
|
|
|
frotation = font.frotation;
|
|
|
|
fshear = font.fshear;
|
2005-01-21 16:13:08 +03:00
|
|
|
fFlags = font.fFlags;
|
|
|
|
fSpacing = font.fSpacing;
|
|
|
|
fDirection = B_FONT_LEFT_TO_RIGHT;
|
|
|
|
fFace = B_REGULAR_FACE;
|
|
|
|
fEncoding = B_UNICODE_UTF8;
|
|
|
|
fBounds.Set(0,0,0,0);
|
|
|
|
if(fStyle)
|
|
|
|
fStyle->AddDependent();
|
2003-09-15 23:09:13 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2003-01-01 01:19:48 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the number of strikes in the font
|
|
|
|
\return The number of strikes in the font
|
|
|
|
*/
|
|
|
|
int32 ServerFont::CountTuned(void)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
if(fStyle)
|
|
|
|
fStyle->TunedCount();
|
2003-01-01 01:19:48 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Returns the file format of the font. Currently unimplemented.
|
|
|
|
\return B_TRUETYPE_WINDOWS
|
|
|
|
*/
|
|
|
|
font_file_format ServerFont::FileFormat(void)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
// TODO: implement ServerFont::FileFormat
|
2005-01-17 05:05:50 +03:00
|
|
|
return B_TRUETYPE_WINDOWS;
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Returns a BRect which encloses the entire font
|
|
|
|
\return A BRect which encloses the entire font
|
|
|
|
*/
|
|
|
|
BRect ServerFont::BoundingBox(void)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
return fBounds;
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-01-17 05:05:50 +03:00
|
|
|
const char *ServerFont::GetStyle(void) const
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
return fStyle->Name();
|
2005-01-17 05:05:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ServerFont::GetFamily(void) const
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
return fStyle->Family()->Name();
|
2005-01-17 05:05:50 +03:00
|
|
|
}
|
|
|
|
|
2003-01-01 01:19:48 +03:00
|
|
|
/*!
|
|
|
|
\brief Obtains the height values for characters in the font in its current state
|
2003-01-20 02:04:58 +03:00
|
|
|
\param fh pointer to a font_height object to receive the values for the font
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
|
|
|
void ServerFont::Height(font_height *fh)
|
|
|
|
{
|
2005-01-21 16:13:08 +03:00
|
|
|
if(!fh)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(fStyle)
|
|
|
|
*fh=fStyle->GetHeight(fSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Sets the ServerFont instance to whatever font is specified
|
|
|
|
\param fontID the combination of family and style ID numbers
|
|
|
|
*/
|
|
|
|
void ServerFont::SetFamilyAndStyle(const uint32 &fontID)
|
|
|
|
{
|
|
|
|
uint16 style = fontID & 0xFFFF;
|
|
|
|
uint16 family = (fontID & 0xFFFF0000) >> 16;
|
|
|
|
|
|
|
|
fontserver->Lock();
|
|
|
|
FontStyle *sty=fontserver->GetStyle(family,style);
|
|
|
|
fontserver->Unlock();
|
|
|
|
if(sty)
|
|
|
|
fStyle=sty;
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
2005-01-23 16:40:11 +03:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Gets the ID values for the ServerFont instance in one shot
|
|
|
|
\return the combination of family and style ID numbers
|
|
|
|
*/
|
|
|
|
uint32 ServerFont::GetFamilyAndStyle(void)
|
|
|
|
{
|
|
|
|
uint32 famsty=0;
|
|
|
|
|
|
|
|
famsty|=FamilyID() << 16;
|
|
|
|
famsty|=StyleID();
|
|
|
|
|
|
|
|
return famsty;
|
|
|
|
}
|
|
|
|
|