Added two DrawStringDry() versions for obtaining pen location only

When recording into a BPicture (ServerPicture, actually), one cannot
simply record the commands only, when the drawing itself would modify
state. This affects all drawing commands that change the pen location.
Therefore it is necessary to have a way to "dry-run" drawing a string
in order to know the pen location that would result. This is what
these two new methods help achieve.

Change-Id: Ic399a5513f18c12c16c0ab10a55e768c1b30e4e0
Reviewed-on: https://review.haiku-os.org/816
Reviewed-by: Rene Gollent <rene@gollent.com>
This commit is contained in:
Stephan Aßmus 2019-01-02 18:44:14 +01:00 committed by Rene Gollent
parent 6990ae7b84
commit f8550e541b
2 changed files with 44 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2015, Haiku, Inc.
* Copyright 2001-2018, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -1409,7 +1409,7 @@ DrawingEngine::DrawString(const char* string, int32 length,
{
ASSERT_PARALLEL_LOCKED();
// use a FontCacheRefernece to speed up the second pass of
// use a FontCacheReference to speed up the second pass of
// drawing the string
FontCacheReference cacheReference;
@ -1450,6 +1450,40 @@ DrawingEngine::StringWidth(const char* string, int32 length,
}
BPoint
DrawingEngine::DrawStringDry(const char* string, int32 length,
const BPoint& pt, escapement_delta* delta)
{
ASSERT_PARALLEL_LOCKED();
BPoint penLocation = pt;
// try a fast path first
if (fPainter->Font().Rotation() == 0.0f
&& fPainter->IsIdentityTransform()) {
penLocation.x += StringWidth(string, length, delta);
return penLocation;
}
fPainter->BoundingBox(string, length, pt, &penLocation, delta, NULL);
return penLocation;
}
BPoint
DrawingEngine::DrawStringDry(const char* string, int32 length,
const BPoint* offsets)
{
ASSERT_PARALLEL_LOCKED();
BPoint penLocation;
fPainter->BoundingBox(string, length, offsets, &penLocation, NULL);
return penLocation;
}
// #pragma mark -

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2015, Haiku, Inc.
* Copyright 2001-2018, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -184,6 +184,13 @@ public:
int32 length, const ServerFont& font,
escapement_delta* delta = NULL);
BPoint DrawStringDry(const char* string, int32 length,
const BPoint& pt,
escapement_delta* delta = NULL);
BPoint DrawStringDry(const char* string, int32 length,
const BPoint* offsets);
// software rendering backend invoked by CopyRegion() for the sorted
// individual rects
virtual BRect CopyRect(BRect rect, int32 xOffset,