2005-06-24 07:31:41 +04:00
|
|
|
/*
|
2007-08-02 23:10:38 +04:00
|
|
|
* Copyright 2001-2007, Haiku.
|
2005-06-24 07:31:41 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
2005-10-20 13:39:12 +04:00
|
|
|
* Jérôme Duval, jerome.duval@free.fr
|
2006-02-06 02:36:59 +03:00
|
|
|
* Michael Lotz <mmlr@mlotz.ch>
|
2007-08-02 23:10:38 +04:00
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
2005-06-24 07:31:41 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-04-26 14:16:19 +04:00
|
|
|
#include "ServerFont.h"
|
2005-05-12 19:09:30 +04:00
|
|
|
|
2005-04-01 11:00:32 +04:00
|
|
|
#include "Angle.h"
|
2007-08-02 23:10:38 +04:00
|
|
|
#include "GlyphLayoutEngine.h"
|
2005-11-02 16:25:39 +03:00
|
|
|
#include "FontManager.h"
|
2005-06-03 23:50:30 +04:00
|
|
|
#include "truncate_string.h"
|
2006-04-26 14:16:19 +04:00
|
|
|
#include "utf8_functions.h"
|
2005-05-12 19:09:30 +04:00
|
|
|
|
2005-04-01 11:00:32 +04:00
|
|
|
#include FT_FREETYPE_H
|
2005-11-10 20:32:35 +03:00
|
|
|
#include FT_GLYPH_H
|
2005-04-01 11:00:32 +04:00
|
|
|
#include FT_OUTLINE_H
|
2003-01-01 01:19:48 +03:00
|
|
|
|
2006-04-26 14:16:19 +04:00
|
|
|
#include <Shape.h>
|
|
|
|
#include <String.h>
|
|
|
|
#include <UTF8.h>
|
2005-05-12 19:09:30 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
#include <agg_bounding_rect.h>
|
|
|
|
|
2007-07-19 06:06:32 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2005-05-12 19:09:30 +04:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
// functions needed to convert a freetype vector graphics to a BShape
|
|
|
|
inline BPoint
|
2006-06-27 15:34:35 +04:00
|
|
|
VectorToPoint(const FT_Vector *vector)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
|
|
|
BPoint result;
|
2006-02-05 01:20:00 +03:00
|
|
|
result.x = float(vector->x) / 64;
|
|
|
|
result.y = -float(vector->y) / 64;
|
2005-06-24 07:31:41 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
int
|
2006-06-27 15:34:35 +04:00
|
|
|
MoveToFunc(const FT_Vector *to, void *user)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
|
|
|
((BShape *)user)->MoveTo(VectorToPoint(to));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
int
|
2006-06-27 15:34:35 +04:00
|
|
|
LineToFunc(const FT_Vector *to, void *user)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
|
|
|
((BShape *)user)->LineTo(VectorToPoint(to));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
int
|
2006-06-27 15:34:35 +04:00
|
|
|
ConicToFunc(const FT_Vector *control, const FT_Vector *to, void *user)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
|
|
|
BPoint controls[3];
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
controls[0] = VectorToPoint(control);
|
|
|
|
controls[1] = VectorToPoint(to);
|
|
|
|
controls[2] = controls[1];
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
((BShape *)user)->BezierTo(controls);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
int
|
2006-06-27 15:34:35 +04:00
|
|
|
CubicToFunc(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *user)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
|
|
|
BPoint controls[3];
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
controls[0] = VectorToPoint(control1);
|
|
|
|
controls[1] = VectorToPoint(control2);
|
|
|
|
controls[2] = VectorToPoint(to);
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
((BShape *)user)->BezierTo(controls);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
2006-02-23 12:04:26 +03:00
|
|
|
is_white_space(uint32 charCode)
|
2005-06-24 07:31:41 +04:00
|
|
|
{
|
2006-02-23 12:04:26 +03:00
|
|
|
switch (charCode) {
|
|
|
|
case 0x0009: /* tab */
|
|
|
|
case 0x000b: /* vertical tab */
|
|
|
|
case 0x000c: /* form feed */
|
|
|
|
case 0x0020: /* space */
|
|
|
|
case 0x00a0: /* non breaking space */
|
|
|
|
case 0x000a: /* line feed */
|
|
|
|
case 0x000d: /* carriage return */
|
|
|
|
case 0x2028: /* line separator */
|
|
|
|
case 0x2029: /* paragraph separator */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2005-11-03 16:10:28 +03:00
|
|
|
ServerFont::ServerFont(FontStyle& style, float size,
|
2006-12-18 08:22:13 +03:00
|
|
|
float rotation, float shear, float falseBoldWidth,
|
2005-06-03 23:50:30 +04:00
|
|
|
uint16 flags, uint8 spacing)
|
2005-11-03 16:10:28 +03:00
|
|
|
: fStyle(&style),
|
2005-06-03 23:50:30 +04:00
|
|
|
fSize(size),
|
|
|
|
fRotation(rotation),
|
|
|
|
fShear(shear),
|
2006-12-18 08:22:13 +03:00
|
|
|
fFalseBoldWidth(falseBoldWidth),
|
2005-06-03 23:50:30 +04:00
|
|
|
fBounds(0, 0, 0, 0),
|
|
|
|
fFlags(flags),
|
|
|
|
fSpacing(spacing),
|
2005-11-09 23:10:40 +03:00
|
|
|
fDirection(style.Direction()),
|
|
|
|
fFace(style.Face()),
|
2005-06-03 23:50:30 +04:00
|
|
|
fEncoding(B_UNICODE_UTF8)
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
fStyle->Acquire();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-04-14 04:22:01 +04:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
ServerFont::ServerFont()
|
2005-11-03 16:10:28 +03:00
|
|
|
:
|
|
|
|
fStyle(NULL)
|
2003-10-05 21:51:13 +04:00
|
|
|
{
|
2005-11-09 22:16:25 +03:00
|
|
|
*this = *gFontManager->DefaultPlainFont();
|
2003-10-05 21:51:13 +04:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03: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-11-03 16:10:28 +03:00
|
|
|
:
|
|
|
|
fStyle(NULL)
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
*this = font;
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
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
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
ServerFont::~ServerFont()
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
fStyle->Release();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +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
|
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
ServerFont&
|
|
|
|
ServerFont::operator=(const ServerFont& font)
|
|
|
|
{
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
if (font.fStyle) {
|
2006-12-18 08:22:13 +03:00
|
|
|
fSize = font.fSize;
|
|
|
|
fRotation = font.fRotation;
|
|
|
|
fShear = font.fShear;
|
|
|
|
fFalseBoldWidth = font.fFalseBoldWidth;
|
|
|
|
fFlags = font.fFlags;
|
|
|
|
fSpacing = font.fSpacing;
|
|
|
|
fEncoding = font.fEncoding;
|
|
|
|
fBounds = font.fBounds;
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
|
|
|
|
SetStyle(font.fStyle);
|
|
|
|
}
|
|
|
|
|
2003-09-15 23:09:13 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
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
|
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
int32
|
|
|
|
ServerFont::CountTuned()
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
return fStyle->TunedCount();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2003-01-01 01:19:48 +03:00
|
|
|
/*!
|
2005-11-03 16:10:28 +03:00
|
|
|
\brief Returns the file format of the font.
|
|
|
|
\return Mostly B_TRUETYPE_WINDOWS :)
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
font_file_format
|
|
|
|
ServerFont::FileFormat()
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
return fStyle->FileFormat();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
const char*
|
2005-11-09 23:10:40 +03:00
|
|
|
ServerFont::Style() const
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
return fStyle->Name();
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
const char*
|
2005-11-09 23:10:40 +03:00
|
|
|
ServerFont::Family() const
|
2005-01-17 05:05:50 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
return fStyle->Family()->Name();
|
2005-01-17 05:05:50 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
void
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
ServerFont::SetStyle(FontStyle* style)
|
2005-11-03 20:03:36 +03:00
|
|
|
{
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
if (style && style != fStyle) {
|
2005-11-03 20:03:36 +03:00
|
|
|
// detach from old style
|
|
|
|
if (fStyle)
|
|
|
|
fStyle->Release();
|
|
|
|
|
|
|
|
// attach to new style
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
fStyle = style;
|
2005-11-09 23:10:40 +03:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
fStyle->Acquire();
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
|
|
|
|
fFace = fStyle->Face();
|
|
|
|
fDirection = fStyle->Direction();
|
2005-11-03 20:03:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
/*!
|
|
|
|
\brief Sets the ServerFont instance to whatever font is specified
|
2006-10-12 16:34:19 +04:00
|
|
|
This method will lock the font manager.
|
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
\param familyID ID number of the family to set
|
|
|
|
\param styleID ID number of the style to set
|
|
|
|
\return B_OK if successful, B_ERROR if not
|
|
|
|
*/
|
|
|
|
status_t
|
|
|
|
ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID)
|
2005-01-17 05:05:50 +03:00
|
|
|
{
|
2005-06-03 23:50:30 +04:00
|
|
|
FontStyle* style = NULL;
|
|
|
|
|
2005-11-02 16:25:39 +03:00
|
|
|
if (gFontManager->Lock()) {
|
|
|
|
style = gFontManager->GetStyle(familyID, styleID);
|
2005-11-03 16:10:28 +03:00
|
|
|
if (style != NULL)
|
|
|
|
style->Acquire();
|
|
|
|
|
2005-11-02 16:25:39 +03:00
|
|
|
gFontManager->Unlock();
|
2005-06-03 23:50:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!style)
|
|
|
|
return B_ERROR;
|
|
|
|
|
ServerFont:
* fixed weird pointer conversion in SetStyle()
* fixed a potential mix up in operator=() in case the
other ServerFont has fStyle == NULL
ServerWindow:
* the WindowLayer fTopLayer cannot be deleted by
client request, just for safety reasons
* the link is flushed if there is no drawing engine,
but this case is theoretical only
* deleting the ServerWindow object syncs with the
client, so that when BBitmaps are deleted, they
can be sure there are no pending messages (which
would be executed in a nother thread)
* there is no timeout anymore when sending messages
to the client, which made absolutely no sense
AGGTextRenderer:
* renamed fFontManager to fFontCache, because that's
what it really is
* fLastFamilyAndStyle defaulted to the system plain
font and therefor that font was never loaded when
the font never changed meanwhile
DrawingMode:
* I'm not quite sure but I think there was the
potential of a division by zero, at least I
had crashes with "divide error"
HWInterface:
* fix update when the cursor shape changed in
double buffered mode
ViewLayer:
* since the top layer is never really deleted
before its time has come, it is not necessary
to set it to NULL in the ViewLayer destructor
ViewLayer/WindowLayer:
* added a function to collect the view tokens
that are affected by an update session
EventDispatcher:
* use the importance of the message for the timeout
in _SendMessage()
* drop mouse moved events in the server if we're
lagging behind more than 5 ms (Axel, maybe review)
View:
* there were some problems with the locking
of the BWindow looper in RemoveSelf(), since
this is called from the window destructor,
also of BWindows from BBitmaps, which have
never been run (this might need review), at
least I seem to have solved the crashing
problems introduced by actually deleting the
view hirarchy in the BWindow destructor
* fixed _Draw() for being used non-recursively,
temporarily disabled DrawAfterChildren, which
didn't work yet anyways (because views cannot
draw over children in the server yet)
Window:
* small cleanup when deleting shortcuts
* sync with the server when having send
AS_DELETE_WINDOW (see ServerWindow above)
* fixed locking in Begin/EndViewTransaction()
* removed folding of _UPDATE_ messages, since
there is only one ever in the queue
* set the fInTransaction flag during an update,
I plan to use this in BView later to
flush the link when drawing outside of an
update
* BView::_Draw() is now called by view token,
this gives the next leap forward in speed,
the overhead because of drawing clean views
was considerable
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15878 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-01-09 01:04:52 +03:00
|
|
|
SetStyle(style);
|
2005-11-03 16:10:28 +03:00
|
|
|
style->Release();
|
2005-06-03 23:50:30 +04:00
|
|
|
|
|
|
|
return B_OK;
|
2005-01-17 05:05:50 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
/*!
|
|
|
|
\brief Sets the ServerFont instance to whatever font is specified
|
|
|
|
\param fontID the combination of family and style ID numbers
|
|
|
|
\return B_OK if successful, B_ERROR if not
|
2003-01-01 01:19:48 +03:00
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
status_t
|
|
|
|
ServerFont::SetFamilyAndStyle(uint32 fontID)
|
2003-01-01 01:19:48 +03:00
|
|
|
{
|
2005-06-03 23:50:30 +04:00
|
|
|
uint16 style = fontID & 0xFFFF;
|
|
|
|
uint16 family = (fontID & 0xFFFF0000) >> 16;
|
2005-01-21 16:13:08 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
return SetFamilyAndStyle(family, style);
|
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-11-09 23:10:40 +03:00
|
|
|
void
|
|
|
|
ServerFont::SetFace(uint32 face)
|
|
|
|
{
|
|
|
|
// TODO: change font style as requested!
|
|
|
|
fFace = face;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
/*!
|
|
|
|
\brief Gets the ID values for the ServerFont instance in one shot
|
|
|
|
\return the combination of family and style ID numbers
|
|
|
|
*/
|
|
|
|
uint32
|
2006-02-06 02:36:59 +03:00
|
|
|
ServerFont::GetFamilyAndStyle() const
|
2005-06-03 23:50:30 +04:00
|
|
|
{
|
|
|
|
return (FamilyID() << 16) | StyleID();
|
2005-01-21 16:13:08 +03:00
|
|
|
}
|
|
|
|
|
2005-04-01 11:00:32 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
FT_Face
|
|
|
|
ServerFont::GetTransformedFace(bool rotate, bool shear) const
|
2005-04-01 11:00:32 +04:00
|
|
|
{
|
2006-02-06 20:42:18 +03:00
|
|
|
fStyle->Lock();
|
|
|
|
FT_Face face = fStyle->FreeTypeFace();
|
|
|
|
if (!face) {
|
|
|
|
fStyle->Unlock();
|
2005-04-01 11:00:32 +04:00
|
|
|
return NULL;
|
2006-02-06 20:42:18 +03:00
|
|
|
}
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2005-06-15 21:09:00 +04:00
|
|
|
FT_Set_Char_Size(face, 0, int32(fSize * 64), 72, 72);
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
if ((rotate && fRotation != 0) || (shear && fShear != 90)) {
|
|
|
|
FT_Matrix rmatrix, smatrix;
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
Angle rotationAngle(fRotation);
|
|
|
|
rmatrix.xx = (FT_Fixed)( rotationAngle.Cosine() * 0x10000);
|
|
|
|
rmatrix.xy = (FT_Fixed)(-rotationAngle.Sine() * 0x10000);
|
|
|
|
rmatrix.yx = (FT_Fixed)( rotationAngle.Sine() * 0x10000);
|
|
|
|
rmatrix.yy = (FT_Fixed)( rotationAngle.Cosine() * 0x10000);
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
Angle shearAngle(fShear);
|
|
|
|
smatrix.xx = (FT_Fixed)(0x10000);
|
|
|
|
smatrix.xy = (FT_Fixed)(-shearAngle.Cosine() * 0x10000);
|
|
|
|
smatrix.yx = (FT_Fixed)(0);
|
|
|
|
smatrix.yy = (FT_Fixed)(0x10000);
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
// Multiply togheter and apply transform
|
|
|
|
FT_Matrix_Multiply(&rmatrix, &smatrix);
|
|
|
|
FT_Set_Transform(face, &smatrix, NULL);
|
|
|
|
}
|
|
|
|
|
* completed my changes to DrawState handling, the current DrawingState
of the active ViewLayer is now always mirrored in the Painter instance
of a ServerWindow, so that it doesn't need to be synced on every drawing
command, this was previously incomplete for font handling
* removed the DrawState parameter from all the DrawingEngine functions
* adjusted ServerWindow and ServerPicture accordingly
* made sure that string related functions used by non-drawing related
parts (ServerApp, Decorator) don't interfere with the current drawing
state
* moved AS_SYNC handling from _DispatchViewMessage to _DispatchMessage,
it is actually a window message and doesn't require fCurrentLayer to
be valid
* fixed bug #1300, fCurrentLayer was not updated when a ViewLayer was
deleted by client request which happened to be fCurrentLayer (I am now
handling it so that the parent becomes the current layer, could be
wrong)
* AGGTextRenderer is no longer using it's own scanline, which should save
a few bytes RAM, the Painter already had such an object
* StringWidth() in AGGTextRenderer is now taking the escapement_delta into
account
* Painter::StrokeLine() doesn't need to check the clipping as much, since
that is already done in DrawingEngine
* if a ServerWindow message is not handled because fCurrentLayer is NULL,
a reply is sent in case the messages needs it (client window could
freeze otherwise, waiting for the reply for ever)
* removed unused AS_SET_FONT and AS_SET_FONT_SIZE
* added automatic RGBColor -> rgb_color conversion to RGBColor.h
* minor cleanup for 80 char/line limit
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21685 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-07-22 23:48:27 +04:00
|
|
|
// fStyle will be unlocked in PutTransformedFace()
|
2006-02-06 02:36:59 +03:00
|
|
|
return face;
|
|
|
|
}
|
2006-02-05 01:20:00 +03:00
|
|
|
|
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
void
|
|
|
|
ServerFont::PutTransformedFace(FT_Face face) const
|
|
|
|
{
|
|
|
|
// Reset transformation
|
2006-02-06 20:42:18 +03:00
|
|
|
FT_Set_Transform(face, NULL, NULL);
|
|
|
|
fStyle->Unlock();
|
2006-02-06 02:36:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
ServerFont::GetGlyphShapes(const char charArray[], int32 numChars,
|
|
|
|
BShape *shapeArray[]) const
|
|
|
|
{
|
|
|
|
if (!charArray || numChars <= 0 || !shapeArray)
|
|
|
|
return B_BAD_DATA;
|
|
|
|
|
|
|
|
FT_Face face = GetTransformedFace(true, true);
|
|
|
|
if (!face)
|
|
|
|
return B_ERROR;
|
|
|
|
|
|
|
|
FT_Outline_Funcs funcs;
|
|
|
|
funcs.move_to = MoveToFunc;
|
|
|
|
funcs.line_to = LineToFunc;
|
|
|
|
funcs.conic_to = ConicToFunc;
|
|
|
|
funcs.cubic_to = CubicToFunc;
|
|
|
|
funcs.shift = 0;
|
|
|
|
funcs.delta = 0;
|
|
|
|
|
|
|
|
const char *string = charArray;
|
|
|
|
for (int i = 0; i < numChars; i++) {
|
|
|
|
shapeArray[i] = new BShape();
|
|
|
|
FT_Load_Char(face, UTF8ToCharCode(&string), FT_LOAD_NO_BITMAP);
|
2005-04-01 11:00:32 +04:00
|
|
|
FT_Outline outline = face->glyph->outline;
|
2006-02-06 02:36:59 +03:00
|
|
|
FT_Outline_Decompose(&outline, &funcs, shapeArray[i]);
|
|
|
|
shapeArray[i]->Close();
|
2005-04-01 11:00:32 +04:00
|
|
|
}
|
2006-02-05 01:20:00 +03:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
PutTransformedFace(face);
|
|
|
|
return B_OK;
|
2005-04-01 11:00:32 +04:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:22:55 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
status_t
|
|
|
|
ServerFont::GetHasGlyphs(const char charArray[], int32 numChars,
|
|
|
|
bool hasArray[]) const
|
2005-07-19 19:22:55 +04:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
if (!charArray || numChars <= 0 || !hasArray)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_BAD_DATA;
|
2005-07-19 19:22:55 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
FT_Face face = GetTransformedFace(false, false);
|
2005-08-24 01:47:41 +04:00
|
|
|
if (!face)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_ERROR;
|
2005-07-19 19:22:55 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
const char *string = charArray;
|
|
|
|
for (int i = 0; i < numChars; i++)
|
|
|
|
hasArray[i] = FT_Get_Char_Index(face, UTF8ToCharCode(&string)) > 0;
|
2005-08-24 01:47:41 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
PutTransformedFace(face);
|
|
|
|
return B_OK;
|
2005-08-24 18:50:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
class EdgesConsumer {
|
|
|
|
public:
|
|
|
|
EdgesConsumer(edge_info* edges, float size)
|
|
|
|
: fEdges(edges)
|
|
|
|
, fSize(size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Start() {}
|
|
|
|
void Finish(double x, double y) {}
|
|
|
|
void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y)
|
|
|
|
{
|
|
|
|
fEdges[index].left = 0.0;
|
|
|
|
fEdges[index].right = 0.0;
|
|
|
|
}
|
|
|
|
bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph,
|
|
|
|
FontCacheEntry* entry, double x, double y)
|
|
|
|
{
|
|
|
|
fEdges[index].left = glyph->inset_left / fSize;
|
|
|
|
fEdges[index].right = glyph->inset_right / fSize;
|
|
|
|
return true;
|
2005-08-24 18:50:41 +04:00
|
|
|
}
|
2006-02-06 02:36:59 +03:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
private:
|
|
|
|
edge_info* fEdges;
|
|
|
|
float fSize;
|
|
|
|
};
|
2005-07-19 19:22:55 +04:00
|
|
|
|
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
status_t
|
2007-08-03 05:11:27 +04:00
|
|
|
ServerFont::GetEdges(const char* string, int32 numChars,
|
|
|
|
edge_info* edges) const
|
2005-04-01 13:18:25 +04:00
|
|
|
{
|
2007-08-03 05:11:27 +04:00
|
|
|
if (!string || numChars <= 0 || !edges)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_BAD_DATA;
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
bool kerning = true; // TODO make this a property?
|
|
|
|
|
|
|
|
EdgesConsumer consumer(edges, fSize);
|
|
|
|
if (GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
NULL, kerning, fSpacing))
|
|
|
|
return B_OK;
|
|
|
|
|
|
|
|
return B_ERROR;
|
|
|
|
|
|
|
|
// FT_Face face = GetTransformedFace(false, false);
|
|
|
|
// if (!face)
|
|
|
|
// return B_ERROR;
|
|
|
|
//
|
|
|
|
// const char *string = charArray;
|
|
|
|
// for (int i = 0; i < numChars; i++) {
|
|
|
|
// FT_Load_Char(face, UTF8ToCharCode(&string), FT_LOAD_NO_BITMAP);
|
|
|
|
// edgeArray[i].left = float(face->glyph->metrics.horiBearingX)
|
|
|
|
// / 64 / fSize;
|
|
|
|
// edgeArray[i].right = float(face->glyph->metrics.horiBearingX
|
|
|
|
// + face->glyph->metrics.width - face->glyph->metrics.horiAdvance)
|
|
|
|
// / 64 / fSize;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// PutTransformedFace(face);
|
|
|
|
// return B_OK;
|
|
|
|
}
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
|
|
|
|
class BPointEscapementConsumer {
|
|
|
|
public:
|
|
|
|
BPointEscapementConsumer(BPoint* escapements, BPoint* offsets, float size)
|
|
|
|
: fEscapements(escapements)
|
|
|
|
, fOffsets(offsets)
|
|
|
|
, fSize(size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Start() {}
|
|
|
|
void Finish(double x, double y) {}
|
|
|
|
void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y)
|
|
|
|
{
|
|
|
|
_Set(index, 0, 0);
|
|
|
|
}
|
|
|
|
bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph,
|
|
|
|
FontCacheEntry* entry, double x, double y)
|
|
|
|
{
|
|
|
|
_Set(index, glyph->advance_x, glyph->advance_y);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
inline void _Set(int32 index, double x, double y)
|
|
|
|
{
|
|
|
|
fEscapements[index].x = x / fSize;
|
|
|
|
fEscapements[index].y = y / fSize;
|
|
|
|
if (fOffsets) {
|
2006-02-06 02:36:59 +03:00
|
|
|
// ToDo: According to the BeBook: "The offsetArray is applied by
|
|
|
|
// the dynamic spacing in order to improve the relative position
|
|
|
|
// of the character's width with relation to another character,
|
|
|
|
// without altering the width." So this will probably depend on
|
|
|
|
// the spacing mode.
|
2007-08-03 05:11:27 +04:00
|
|
|
fOffsets[index].x = 0;
|
|
|
|
fOffsets[index].y = 0;
|
2006-02-06 02:36:59 +03:00
|
|
|
}
|
2005-04-01 13:18:25 +04:00
|
|
|
}
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
BPoint* fEscapements;
|
|
|
|
BPoint* fOffsets;
|
|
|
|
float fSize;
|
|
|
|
};
|
2005-04-01 13:18:25 +04:00
|
|
|
|
2005-05-16 15:03:28 +04:00
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
status_t
|
2007-08-03 05:11:27 +04:00
|
|
|
ServerFont::GetEscapements(const char* string, int32 numChars,
|
|
|
|
escapement_delta delta, BPoint escapementArray[],
|
|
|
|
BPoint offsetArray[]) const
|
2005-05-12 19:09:30 +04:00
|
|
|
{
|
2007-08-03 05:11:27 +04:00
|
|
|
if (!string || numChars <= 0 || !escapementArray)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_BAD_DATA;
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
bool kerning = true; // TODO make this a property?
|
2005-05-12 19:09:30 +04:00
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
BPointEscapementConsumer consumer(escapementArray, offsetArray, fSize);
|
|
|
|
if (GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
&delta, kerning, fSpacing))
|
|
|
|
return B_OK;
|
|
|
|
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class WidthEscapementConsumer {
|
|
|
|
public:
|
|
|
|
WidthEscapementConsumer(float* widths, float size)
|
|
|
|
: fWidths(widths)
|
|
|
|
, fSize(size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Start() {}
|
|
|
|
void Finish(double x, double y) {}
|
|
|
|
void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y)
|
|
|
|
{
|
|
|
|
fWidths[index] = 0.0;
|
|
|
|
}
|
|
|
|
bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph,
|
|
|
|
FontCacheEntry* entry, double x, double y)
|
|
|
|
{
|
|
|
|
fWidths[index] = glyph->advance_x / fSize;
|
|
|
|
return true;
|
2005-05-12 19:09:30 +04:00
|
|
|
}
|
|
|
|
|
2007-08-03 05:11:27 +04:00
|
|
|
private:
|
|
|
|
float* fWidths;
|
|
|
|
float fSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
ServerFont::GetEscapements(const char* string, int32 numChars,
|
|
|
|
escapement_delta delta, float widthArray[]) const
|
|
|
|
{
|
|
|
|
if (!string || numChars <= 0 || !widthArray)
|
|
|
|
return B_BAD_DATA;
|
|
|
|
|
|
|
|
bool kerning = true; // TODO make this a property?
|
|
|
|
|
|
|
|
WidthEscapementConsumer consumer(widthArray, fSize);
|
|
|
|
if (GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
&delta, kerning, fSpacing))
|
|
|
|
return B_OK;
|
|
|
|
return B_ERROR;
|
2005-05-12 19:09:30 +04:00
|
|
|
}
|
|
|
|
|
2005-08-25 19:21:34 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
class BoundingBoxConsumer {
|
|
|
|
public:
|
|
|
|
BoundingBoxConsumer(Transformable& transform, BRect* rectArray,
|
|
|
|
bool asString)
|
|
|
|
: rectArray(rectArray)
|
|
|
|
, stringBoundingBox(LONG_MAX, LONG_MAX, LONG_MIN, LONG_MIN)
|
|
|
|
, fAsString(asString)
|
|
|
|
, fCurves(fPathAdaptor)
|
|
|
|
, fContour(fCurves)
|
|
|
|
, fTransformedOutline(fCurves, transform)
|
|
|
|
, fTransformedContourOutline(fContour, transform)
|
|
|
|
, fTransform(transform)
|
|
|
|
{
|
|
|
|
}
|
2007-08-07 05:24:09 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
void Start() {}
|
|
|
|
void Finish(double x, double y) {}
|
|
|
|
void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y) {}
|
|
|
|
bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph,
|
|
|
|
FontCacheEntry* entry, double x, double y)
|
|
|
|
{
|
|
|
|
if (glyph->data_type != glyph_data_outline) {
|
|
|
|
const agg::rect_i& r = glyph->bounds;
|
|
|
|
if (fAsString) {
|
|
|
|
if (rectArray) {
|
2007-08-07 05:24:09 +04:00
|
|
|
rectArray[index].left = r.x1 + x;
|
|
|
|
rectArray[index].top = r.y1 + y;
|
|
|
|
rectArray[index].right = r.x2 + x + 1;
|
|
|
|
rectArray[index].bottom = r.y2 + y + 1;
|
2007-08-02 23:10:38 +04:00
|
|
|
} else {
|
|
|
|
stringBoundingBox = stringBoundingBox
|
2007-08-03 05:11:27 +04:00
|
|
|
| BRect(r.x1 + x, r.y1 + y,
|
2007-08-02 23:10:38 +04:00
|
|
|
r.x2 + x + 1, r.y2 + y + 1);
|
|
|
|
}
|
2007-08-07 05:24:09 +04:00
|
|
|
} else {
|
|
|
|
rectArray[index].left = r.x1;
|
|
|
|
rectArray[index].top = r.y1;
|
|
|
|
rectArray[index].right = r.x2 + 1;
|
|
|
|
rectArray[index].bottom = r.y2 + 1;
|
2007-08-02 23:10:38 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fAsString) {
|
|
|
|
entry->InitAdaptors(glyph, x, y,
|
|
|
|
fMonoAdaptor, fGray8Adaptor, fPathAdaptor);
|
|
|
|
} else {
|
|
|
|
entry->InitAdaptors(glyph, 0, 0,
|
|
|
|
fMonoAdaptor, fGray8Adaptor, fPathAdaptor);
|
|
|
|
}
|
|
|
|
double left = 0.0;
|
|
|
|
double top = 0.0;
|
|
|
|
double right = -1.0;
|
|
|
|
double bottom = -1.0;
|
|
|
|
uint32 pathID[1];
|
|
|
|
pathID[0] = 0;
|
|
|
|
// TODO: use fContour if falseboldwidth is > 0
|
|
|
|
agg::bounding_rect(fTransformedOutline, pathID, 0, 1,
|
|
|
|
&left, &top, &right, &bottom);
|
|
|
|
|
|
|
|
if (rectArray) {
|
|
|
|
rectArray[index] = BRect(left, top, right, bottom);
|
|
|
|
} else {
|
|
|
|
stringBoundingBox = stringBoundingBox
|
|
|
|
| BRect(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BRect* rectArray;
|
|
|
|
BRect stringBoundingBox;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fAsString;
|
|
|
|
FontCacheEntry::GlyphPathAdapter fPathAdaptor;
|
|
|
|
FontCacheEntry::GlyphGray8Adapter fGray8Adaptor;
|
|
|
|
FontCacheEntry::GlyphMonoAdapter fMonoAdaptor;
|
|
|
|
|
|
|
|
FontCacheEntry::CurveConverter fCurves;
|
|
|
|
FontCacheEntry::ContourConverter fContour;
|
|
|
|
|
|
|
|
FontCacheEntry::TransformedOutline fTransformedOutline;
|
|
|
|
FontCacheEntry::TransformedContourOutline fTransformedContourOutline;
|
|
|
|
|
|
|
|
Transformable& fTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
status_t
|
2007-08-02 23:10:38 +04:00
|
|
|
ServerFont::GetBoundingBoxes(const char* string, int32 numChars,
|
2006-02-06 02:36:59 +03:00
|
|
|
BRect rectArray[], bool stringEscapement, font_metric_mode mode,
|
2007-08-02 23:10:38 +04:00
|
|
|
escapement_delta delta, bool asString)
|
2005-08-25 19:21:34 +04:00
|
|
|
{
|
2007-08-02 23:10:38 +04:00
|
|
|
// TODO: The font_metric_mode is not used
|
|
|
|
if (!string || numChars <= 0 || !rectArray)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_BAD_DATA;
|
2005-08-25 19:21:34 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
bool kerning = true; // TODO make this a property?
|
2006-02-06 02:36:59 +03:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
Transformable transform(EmbeddedTransformation());
|
2005-08-25 19:21:34 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
BoundingBoxConsumer consumer(transform, rectArray, asString);
|
|
|
|
if (GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
stringEscapement ? &delta : NULL, kerning, fSpacing))
|
|
|
|
return B_OK;
|
|
|
|
return B_ERROR;
|
2005-08-25 19:21:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
status_t
|
2007-08-07 05:24:09 +04:00
|
|
|
ServerFont::GetBoundingBoxesForStrings(char *charArray[], int32 lengthArray[],
|
|
|
|
int32 numStrings, BRect rectArray[], font_metric_mode mode,
|
|
|
|
escapement_delta deltaArray[])
|
2005-08-25 19:21:34 +04:00
|
|
|
{
|
2007-08-02 23:10:38 +04:00
|
|
|
// TODO: The font_metric_mode is never used
|
2005-11-03 16:10:28 +03:00
|
|
|
if (!charArray || !lengthArray|| numStrings <= 0 || !rectArray || !deltaArray)
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_BAD_DATA;
|
2005-08-25 19:21:34 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
bool kerning = true; // TODO make this a property?
|
|
|
|
|
|
|
|
Transformable transform(EmbeddedTransformation());
|
2005-08-25 19:21:34 +04:00
|
|
|
|
2005-11-03 03:04:18 +03:00
|
|
|
for (int32 i = 0; i < numStrings; i++) {
|
2007-07-19 06:06:32 +04:00
|
|
|
int32 numChars = lengthArray[i];
|
2007-08-02 23:10:38 +04:00
|
|
|
const char* string = charArray[i];
|
2007-07-19 06:06:32 +04:00
|
|
|
escapement_delta delta = deltaArray[i];
|
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
BoundingBoxConsumer consumer(transform, NULL, true);
|
|
|
|
if (!GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
&delta, kerning, fSpacing))
|
|
|
|
return B_ERROR;
|
|
|
|
|
|
|
|
rectArray[i] = consumer.stringBoundingBox;
|
2005-08-26 19:02:53 +04:00
|
|
|
}
|
|
|
|
|
2006-02-06 02:36:59 +03:00
|
|
|
return B_OK;
|
2005-08-25 19:21:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
class StringWidthConsumer {
|
|
|
|
public:
|
|
|
|
StringWidthConsumer() : width(0.0) {}
|
|
|
|
void Start() {}
|
|
|
|
void Finish(double x, double y) { width = x; }
|
|
|
|
void ConsumeEmptyGlyph(int32 index, uint32 charCode, double x, double y) {}
|
|
|
|
bool ConsumeGlyph(int32 index, uint32 charCode, const GlyphCache* glyph,
|
|
|
|
FontCacheEntry* entry, double x, double y)
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
float width;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-05-20 21:36:55 +04:00
|
|
|
float
|
2007-08-02 23:10:38 +04:00
|
|
|
ServerFont::StringWidth(const char *string, int32 numChars,
|
|
|
|
const escapement_delta* deltaArray) const
|
2005-05-20 21:36:55 +04:00
|
|
|
{
|
2007-08-02 23:10:38 +04:00
|
|
|
if (!string || numChars <= 0)
|
2005-05-21 03:51:33 +04:00
|
|
|
return 0.0;
|
2005-05-20 21:36:55 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
bool kerning = true; // TODO make this a property?
|
2005-05-20 21:36:55 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
StringWidthConsumer consumer;
|
|
|
|
if (!GlyphLayoutEngine::LayoutGlyphs(consumer, *this, string, numChars,
|
|
|
|
deltaArray, kerning, fSpacing))
|
|
|
|
return 0.0;
|
2005-05-20 21:36:55 +04:00
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
return consumer.width;
|
2005-05-20 21:36:55 +04:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
/*!
|
|
|
|
\brief Returns a BRect which encloses the entire font
|
|
|
|
\return A BRect which encloses the entire font
|
2005-02-05 23:12:05 +03:00
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
BRect
|
|
|
|
ServerFont::BoundingBox()
|
2005-02-05 23:12:05 +03:00
|
|
|
{
|
2005-06-03 23:50:30 +04:00
|
|
|
// TODO: fBounds is nowhere calculated!
|
|
|
|
return fBounds;
|
2005-02-05 23:12:05 +03:00
|
|
|
}
|
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
/*!
|
|
|
|
\brief Obtains the height values for characters in the font in its current state
|
|
|
|
\param fh pointer to a font_height object to receive the values for the font
|
2005-01-21 16:13:08 +03:00
|
|
|
*/
|
2005-06-03 23:50:30 +04:00
|
|
|
void
|
2005-11-03 16:10:28 +03:00
|
|
|
ServerFont::GetHeight(font_height& height) const
|
2005-01-21 16:13:08 +03:00
|
|
|
{
|
2005-11-03 16:10:28 +03:00
|
|
|
fStyle->GetHeight(fSize, height);
|
2003-01-01 01:19:48 +03:00
|
|
|
}
|
2005-01-23 16:40:11 +03:00
|
|
|
|
2005-11-03 16:10:28 +03:00
|
|
|
|
2005-06-03 23:50:30 +04:00
|
|
|
void
|
|
|
|
ServerFont::TruncateString(BString* inOut, uint32 mode, float width) const
|
2005-01-23 16:40:11 +03:00
|
|
|
{
|
2006-02-06 20:42:18 +03:00
|
|
|
if (!inOut)
|
|
|
|
return;
|
2005-06-03 23:50:30 +04:00
|
|
|
|
2006-02-06 20:42:18 +03:00
|
|
|
// the width of the "…" glyph
|
|
|
|
float ellipsisWidth = StringWidth(B_UTF8_ELLIPSIS, 1);
|
|
|
|
const char *string = inOut->String();
|
|
|
|
int32 length = inOut->Length();
|
|
|
|
|
|
|
|
// temporary array to hold result
|
|
|
|
char *result = new char[length + 3];
|
2005-06-03 23:50:30 +04:00
|
|
|
|
2006-02-06 20:42:18 +03:00
|
|
|
// count the individual glyphs
|
2006-12-26 00:58:00 +03:00
|
|
|
int32 numChars = UTF8CountChars(string, -1);
|
2006-02-06 20:42:18 +03:00
|
|
|
|
|
|
|
// get the escapement of each glyph in font units
|
|
|
|
float *escapementArray = new float[numChars];
|
|
|
|
static escapement_delta delta = (escapement_delta){ 0.0, 0.0 };
|
|
|
|
if (GetEscapements(string, numChars, delta, escapementArray) == B_OK) {
|
|
|
|
truncate_string(string, mode, width, result, escapementArray, fSize,
|
|
|
|
ellipsisWidth, length, numChars);
|
|
|
|
|
|
|
|
inOut->SetTo(result);
|
2005-06-03 23:50:30 +04:00
|
|
|
}
|
2006-02-06 20:42:18 +03:00
|
|
|
|
|
|
|
delete[] escapementArray;
|
|
|
|
delete[] result;
|
2005-01-23 16:40:11 +03:00
|
|
|
}
|
|
|
|
|
2007-08-02 23:10:38 +04:00
|
|
|
|
|
|
|
Transformable
|
|
|
|
ServerFont::EmbeddedTransformation() const
|
|
|
|
{
|
|
|
|
// TODO: cache this?
|
|
|
|
Transformable transform;
|
|
|
|
|
|
|
|
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * PI / 180.0, 0.0);
|
|
|
|
transform.RotateBy(B_ORIGIN, -fRotation * PI / 180.0);
|
|
|
|
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|