Fix some cases of updating draw state while recording a BPicture
* Also implemented recording DrawString(string, length, BPoint[] locations), which was previously not recorded at all. * Also implemented playing back recently added drawing commands in PicturePlayer.cpp. I don't quite understand what this is actually used for, but it seemed it was forgotten. I just followed the pattern already established in the code. * The other important bit in this change is to update the pen location when it is needed while recording a BPicture. Often the BView will use PenLocation() in order to transmit drawing commands to the app_server which use absolute coordinates only. This isn't actually so nice, since it means the client has to wait for the server to transmit the current pen location. If there were dedicated link-commands for pen-relative drawing commands, the client could just keep sending without waiting for the server. In any case, the app_server needs to update the pen location in the current DrawState and even the DrawingEngine even while recording a picture, because some next command may need up-2-date state information, such as the font state and the pen location. * I have not yet tried to find /all/ instances where the DrawState needs to be updated while recording. This change should repair /all/ font state changes, all versions of drawing a string, and all versions of StrokeLine(). Change-Id: Ia0f23e7b1cd058f70f76a5849acb2d02e0f0da09 Reviewed-on: https://review.haiku-os.org/c/817 Reviewed-by: Stephan Aßmus <[email protected]>
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2015 Haiku, Inc. All rights reserved.
|
* Copyright 2006-2018 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stefano Ceccherini, [email protected]
|
* Stefano Ceccherini, [email protected]
|
||||||
* Julian Harnath, <[email protected]>
|
* Julian Harnath, <[email protected]>
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef _PICTURE_DATA_WRITER_H
|
#ifndef _PICTURE_DATA_WRITER_H
|
||||||
#define _PICTURE_DATA_WRITER_H
|
#define _PICTURE_DATA_WRITER_H
|
||||||
@@ -84,6 +85,9 @@ public:
|
|||||||
status_t WriteDrawString(const BPoint& where,
|
status_t WriteDrawString(const BPoint& where,
|
||||||
const char* string, const int32& length,
|
const char* string, const int32& length,
|
||||||
const escapement_delta& delta);
|
const escapement_delta& delta);
|
||||||
|
status_t WriteDrawString(const char* string,
|
||||||
|
int32 length, const BPoint* locations,
|
||||||
|
int32 locationCount);
|
||||||
status_t WriteDrawShape(const int32& opCount,
|
status_t WriteDrawShape(const int32& opCount,
|
||||||
const void* opList, const int32& ptCount,
|
const void* opList, const int32& ptCount,
|
||||||
const void* ptList, const bool& fill);
|
const void* ptList, const bool& fill);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2007, Haiku Inc.
|
* Copyright 2001-2018, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Marc Flerackers ([email protected])
|
* Marc Flerackers ([email protected])
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Marcus Overhagen ([email protected])
|
* Marcus Overhagen ([email protected])
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef _PICTURE_PLAYER_H
|
#ifndef _PICTURE_PLAYER_H
|
||||||
#define _PICTURE_PLAYER_H
|
#define _PICTURE_PLAYER_H
|
||||||
@@ -91,6 +92,8 @@ struct picture_player_callbacks {
|
|||||||
void (*clip_to_rect)(void* userData, const BRect& rect, bool inverse);
|
void (*clip_to_rect)(void* userData, const BRect& rect, bool inverse);
|
||||||
void (*clip_to_shape)(void* userData, int32 opCount, const uint32 opList[],
|
void (*clip_to_shape)(void* userData, int32 opCount, const uint32 opList[],
|
||||||
int32 ptCount, const BPoint ptList[], bool inverse);
|
int32 ptCount, const BPoint ptList[], bool inverse);
|
||||||
|
void (*draw_string_locations)(void* userData, const char* string,
|
||||||
|
size_t length, const BPoint locations[], size_t locationCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ enum {
|
|||||||
B_PIC_FILL_ARC = 0x0114,
|
B_PIC_FILL_ARC = 0x0114,
|
||||||
B_PIC_STROKE_ELLIPSE = 0x0115,
|
B_PIC_STROKE_ELLIPSE = 0x0115,
|
||||||
B_PIC_FILL_ELLIPSE = 0x0116,
|
B_PIC_FILL_ELLIPSE = 0x0116,
|
||||||
|
B_PIC_DRAW_STRING_LOCATIONS = 0x0117,
|
||||||
|
|
||||||
B_PIC_ENTER_STATE_CHANGE = 0x0200,
|
B_PIC_ENTER_STATE_CHANGE = 0x0200,
|
||||||
B_PIC_SET_CLIPPING_RECTS = 0x0201,
|
B_PIC_SET_CLIPPING_RECTS = 0x0201,
|
||||||
@@ -61,7 +62,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const static uint32 kOpsTableSize = 50;
|
const static uint32 kOpsTableSize = 51;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2015 Haiku, Inc. All rights reserved.
|
* Copyright 2006-2018 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stefano Ceccherini, [email protected]
|
* Stefano Ceccherini, [email protected]
|
||||||
* Julian Harnath, <[email protected]>
|
* Julian Harnath, <[email protected]>
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PictureDataWriter.h>
|
#include <PictureDataWriter.h>
|
||||||
@@ -478,6 +479,27 @@ PictureDataWriter::WriteDrawString(const BPoint& where, const char* string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PictureDataWriter::WriteDrawString(const char* string,
|
||||||
|
int32 length, const BPoint* locations, int32 locationCount)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
BeginOp(B_PIC_DRAW_STRING_LOCATIONS);
|
||||||
|
Write<int32>(locationCount);
|
||||||
|
for (int32 i = 0; i < locationCount; i++) {
|
||||||
|
Write<BPoint>(locations[i]);
|
||||||
|
}
|
||||||
|
WriteData(string, length);
|
||||||
|
Write<uint8>(0);
|
||||||
|
EndOp();
|
||||||
|
} catch (status_t& status) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawShape(const int32& opCount, const void* opList,
|
PictureDataWriter::WriteDrawShape(const int32& opCount, const void* opList,
|
||||||
const int32& ptCount, const void* ptList, const bool& fill)
|
const int32& ptCount, const void* ptList, const bool& fill)
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2007, Haiku Inc.
|
* Copyright 2001-2018, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Marc Flerackers ([email protected])
|
* Marc Flerackers ([email protected])
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Marcus Overhagen ([email protected])
|
* Marcus Overhagen ([email protected])
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** PicturePlayer is used to play picture data. */
|
/** PicturePlayer is used to play picture data. */
|
||||||
@@ -454,6 +455,87 @@ set_blending_mode(void* _context, source_alpha alphaSrcMode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_transform(void* _context, const BAffineTransform& transform)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, const BAffineTransform&))
|
||||||
|
context->function_table[48])(context->user_data, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
translate_by(void* _context, double x, double y)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, double, double))
|
||||||
|
context->function_table[49])(context->user_data, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
scale_by(void* _context, double x, double y)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, double, double))
|
||||||
|
context->function_table[50])(context->user_data, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
rotate_by(void* _context, double angleRadians)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, double))
|
||||||
|
context->function_table[51])(context->user_data, angleRadians);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
blend_layer(void* _context, Layer* layer)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, Layer*))
|
||||||
|
context->function_table[52])(context->user_data, layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
clip_to_rect(void* _context, const BRect& rect, bool inverse)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, const BRect&, bool))
|
||||||
|
context->function_table[53])(context->user_data, rect, inverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
clip_to_shape(void* _context, int32 opCount, const uint32 opList[],
|
||||||
|
int32 ptCount, const BPoint ptList[], bool inverse)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
((void (*)(void*, int32, const uint32*, int32, const BPoint*, bool))
|
||||||
|
context->function_table[54])(context->user_data, opCount, opList,
|
||||||
|
ptCount, ptList, inverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
draw_string_locations(void* _context, const char* _string, size_t length,
|
||||||
|
const BPoint* locations, size_t locationCount)
|
||||||
|
{
|
||||||
|
adapter_context* context = reinterpret_cast<adapter_context*>(_context);
|
||||||
|
char* string = strndup(_string, length);
|
||||||
|
|
||||||
|
((void (*)(void*, char*, const BPoint*, size_t))
|
||||||
|
context->function_table[55])(context->user_data, string, locations,
|
||||||
|
locationCount);
|
||||||
|
|
||||||
|
free(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG > 1
|
#if DEBUG > 1
|
||||||
static const char *
|
static const char *
|
||||||
PictureOpToString(int op)
|
PictureOpToString(int op)
|
||||||
@@ -474,6 +556,7 @@ PictureOpToString(int op)
|
|||||||
RETURN_STRING(B_PIC_STROKE_SHAPE);
|
RETURN_STRING(B_PIC_STROKE_SHAPE);
|
||||||
RETURN_STRING(B_PIC_FILL_SHAPE);
|
RETURN_STRING(B_PIC_FILL_SHAPE);
|
||||||
RETURN_STRING(B_PIC_DRAW_STRING);
|
RETURN_STRING(B_PIC_DRAW_STRING);
|
||||||
|
RETURN_STRING(B_PIC_DRAW_STRING_LOCATIONS);
|
||||||
RETURN_STRING(B_PIC_DRAW_PIXELS);
|
RETURN_STRING(B_PIC_DRAW_PIXELS);
|
||||||
RETURN_STRING(B_PIC_DRAW_PICTURE);
|
RETURN_STRING(B_PIC_DRAW_PICTURE);
|
||||||
RETURN_STRING(B_PIC_STROKE_ARC);
|
RETURN_STRING(B_PIC_STROKE_ARC);
|
||||||
@@ -510,6 +593,13 @@ PictureOpToString(int op)
|
|||||||
RETURN_STRING(B_PIC_SET_FONT_SHEAR);
|
RETURN_STRING(B_PIC_SET_FONT_SHEAR);
|
||||||
RETURN_STRING(B_PIC_SET_FONT_BPP);
|
RETURN_STRING(B_PIC_SET_FONT_BPP);
|
||||||
RETURN_STRING(B_PIC_SET_FONT_FACE);
|
RETURN_STRING(B_PIC_SET_FONT_FACE);
|
||||||
|
|
||||||
|
RETURN_STRING(B_PIC_AFFINE_TRANSLATE);
|
||||||
|
RETURN_STRING(B_PIC_AFFINE_SCALE);
|
||||||
|
RETURN_STRING(B_PIC_AFFINE_ROTATE);
|
||||||
|
|
||||||
|
RETURN_STRING(B_PIC_BLEND_LAYER);
|
||||||
|
|
||||||
default: return "Unknown op";
|
default: return "Unknown op";
|
||||||
}
|
}
|
||||||
#undef RETURN_STRING
|
#undef RETURN_STRING
|
||||||
@@ -572,7 +662,15 @@ PicturePlayer::Play(void** callBackTable, int32 tableEntries, void* userData)
|
|||||||
set_font_flags,
|
set_font_flags,
|
||||||
set_font_shear,
|
set_font_shear,
|
||||||
set_font_face,
|
set_font_face,
|
||||||
set_blending_mode
|
set_blending_mode,
|
||||||
|
set_transform,
|
||||||
|
translate_by,
|
||||||
|
scale_by,
|
||||||
|
rotate_by,
|
||||||
|
blend_layer,
|
||||||
|
clip_to_rect,
|
||||||
|
clip_to_shape,
|
||||||
|
draw_string_locations
|
||||||
};
|
};
|
||||||
|
|
||||||
// We don't check if the functions in the table are NULL, but we
|
// We don't check if the functions in the table are NULL, but we
|
||||||
@@ -871,6 +969,24 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case B_PIC_DRAW_STRING_LOCATIONS:
|
||||||
|
{
|
||||||
|
const uint32* pointCount;
|
||||||
|
const BPoint* pointList;
|
||||||
|
const char* string;
|
||||||
|
size_t length;
|
||||||
|
if (callbacks.draw_string_locations == NULL
|
||||||
|
|| !reader.Get(pointCount)
|
||||||
|
|| !reader.Get(pointList, *pointCount)
|
||||||
|
|| !reader.GetRemaining(string, length)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
callbacks.draw_string_locations(userData, string, length,
|
||||||
|
pointList, *pointCount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_PIC_DRAW_PIXELS:
|
case B_PIC_DRAW_PIXELS:
|
||||||
{
|
{
|
||||||
const BRect* sourceRect;
|
const BRect* sourceRect;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku.
|
* Copyright 2001-2019, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Marcus Overhagen <[email protected]>
|
* Marcus Overhagen <[email protected]>
|
||||||
* Julian Harnath <[email protected]>
|
* Julian Harnath <[email protected]>
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ServerPicture.h"
|
#include "ServerPicture.h"
|
||||||
@@ -411,6 +412,23 @@ draw_string(void* _canvas, const char* string, size_t length, float deltaSpace,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
draw_string_locations(void* _canvas, const char* string, size_t length,
|
||||||
|
const BPoint* locations, size_t locationsCount)
|
||||||
|
{
|
||||||
|
Canvas* const canvas = reinterpret_cast<Canvas*>(_canvas);
|
||||||
|
|
||||||
|
BPoint location = canvas->GetDrawingEngine()->DrawString(string, length,
|
||||||
|
locations);
|
||||||
|
|
||||||
|
canvas->PenToScreenTransform().Apply(&location);
|
||||||
|
canvas->CurrentState()->SetPenLocation(location);
|
||||||
|
// the DrawingEngine/Painter does not need to be updated, since this
|
||||||
|
// effects only the view->screen coord conversion, which is handled
|
||||||
|
// by the view only
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_pixels(void* _canvas, const BRect& src, const BRect& _dest, uint32 width,
|
draw_pixels(void* _canvas, const BRect& src, const BRect& _dest, uint32 width,
|
||||||
uint32 height, size_t bytesPerRow, color_space pixelFormat, uint32 options,
|
uint32 height, size_t bytesPerRow, color_space pixelFormat, uint32 options,
|
||||||
@@ -881,7 +899,8 @@ static const BPrivate::picture_player_callbacks kPicturePlayerCallbacks = {
|
|||||||
rotate_by,
|
rotate_by,
|
||||||
blend_layer,
|
blend_layer,
|
||||||
clip_to_rect,
|
clip_to_rect,
|
||||||
clip_to_shape
|
clip_to_shape,
|
||||||
|
draw_string_locations
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1046,68 +1065,46 @@ ServerPicture::SyncState(View* view)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerPicture::SetFontFromLink(BPrivate::LinkReceiver& link)
|
ServerPicture::WriteFontState(const ServerFont& font, uint16 mask)
|
||||||
{
|
{
|
||||||
BeginOp(B_PIC_ENTER_FONT_STATE);
|
BeginOp(B_PIC_ENTER_FONT_STATE);
|
||||||
|
|
||||||
uint16 mask;
|
|
||||||
link.Read<uint16>(&mask);
|
|
||||||
|
|
||||||
if (mask & B_FONT_FAMILY_AND_STYLE) {
|
if (mask & B_FONT_FAMILY_AND_STYLE) {
|
||||||
uint32 fontID;
|
|
||||||
link.Read<uint32>(&fontID);
|
|
||||||
ServerFont font;
|
|
||||||
font.SetFamilyAndStyle(fontID);
|
|
||||||
WriteSetFontFamily(font.Family());
|
WriteSetFontFamily(font.Family());
|
||||||
WriteSetFontStyle(font.Style());
|
WriteSetFontStyle(font.Style());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_SIZE) {
|
if (mask & B_FONT_SIZE) {
|
||||||
float size;
|
WriteSetFontSize(font.Size());
|
||||||
link.Read<float>(&size);
|
|
||||||
WriteSetFontSize(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_SHEAR) {
|
if (mask & B_FONT_SHEAR) {
|
||||||
float shear;
|
WriteSetFontShear(font.Shear());
|
||||||
link.Read<float>(&shear);
|
|
||||||
WriteSetFontShear(shear);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_ROTATION) {
|
if (mask & B_FONT_ROTATION) {
|
||||||
float rotation;
|
WriteSetFontRotation(font.Rotation());
|
||||||
link.Read<float>(&rotation);
|
|
||||||
WriteSetFontRotation(rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_FALSE_BOLD_WIDTH) {
|
if (mask & B_FONT_FALSE_BOLD_WIDTH) {
|
||||||
float falseBoldWidth;
|
// TODO: Implement
|
||||||
link.Read<float>(&falseBoldWidth);
|
// WriteSetFalseBoldWidth(font.FalseBoldWidth());
|
||||||
//SetFalseBoldWidth(falseBoldWidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_SPACING) {
|
if (mask & B_FONT_SPACING) {
|
||||||
uint8 spacing;
|
WriteSetFontSpacing(font.Spacing());
|
||||||
link.Read<uint8>(&spacing);
|
|
||||||
WriteSetFontSpacing(spacing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_ENCODING) {
|
if (mask & B_FONT_ENCODING) {
|
||||||
uint8 encoding;
|
WriteSetFontEncoding(font.Encoding());
|
||||||
link.Read<uint8>((uint8*)&encoding);
|
|
||||||
WriteSetFontEncoding(encoding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_FACE) {
|
if (mask & B_FONT_FACE) {
|
||||||
uint16 face;
|
WriteSetFontFace(font.Face());
|
||||||
link.Read<uint16>(&face);
|
|
||||||
WriteSetFontFace(face);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & B_FONT_FLAGS) {
|
if (mask & B_FONT_FLAGS) {
|
||||||
uint32 flags;
|
WriteSetFontFlags(font.Flags());
|
||||||
link.Read<uint32>(&flags);
|
|
||||||
WriteSetFontFlags(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EndOp();
|
EndOp();
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku.
|
* Copyright 2001-2019, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* DarkWyrm <bpmagic@columbus.rr.com>
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
||||||
* Stefano Ceccherini <stefano.ceccherini@gmail.com>
|
* Stefano Ceccherini <stefano.ceccherini@gmail.com>
|
||||||
* Julian Harnath <julian.harnath@rwth-aachen.de>
|
* Julian Harnath <julian.harnath@rwth-aachen.de>
|
||||||
|
* Stephan Aßmus <superstippi@gmx.de>
|
||||||
*/
|
*/
|
||||||
#ifndef SERVER_PICTURE_H
|
#ifndef SERVER_PICTURE_H
|
||||||
#define SERVER_PICTURE_H
|
#define SERVER_PICTURE_H
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
class BFile;
|
class BFile;
|
||||||
class Canvas;
|
class Canvas;
|
||||||
class ServerApp;
|
class ServerApp;
|
||||||
|
class ServerFont;
|
||||||
class View;
|
class View;
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
@@ -48,7 +50,8 @@ public:
|
|||||||
void ExitStateChange();
|
void ExitStateChange();
|
||||||
|
|
||||||
void SyncState(View* view);
|
void SyncState(View* view);
|
||||||
void SetFontFromLink(BPrivate::LinkReceiver& link);
|
void WriteFontState(const ServerFont& font,
|
||||||
|
uint16 mask);
|
||||||
|
|
||||||
void Play(Canvas* target);
|
void Play(Canvas* target);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2015, Haiku.
|
* Copyright 2001-2019, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -3284,6 +3284,7 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
fCurrentView->CurrentState()->SetPenLocation(location);
|
fCurrentView->CurrentState()->SetPenLocation(location);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case AS_VIEW_SET_PEN_SIZE:
|
case AS_VIEW_SET_PEN_SIZE:
|
||||||
{
|
{
|
||||||
float penSize;
|
float penSize;
|
||||||
@@ -3332,6 +3333,9 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
picture->WriteSetTransform(transform);
|
picture->WriteSetTransform(transform);
|
||||||
|
|
||||||
|
fCurrentView->CurrentState()->SetTransform(transform);
|
||||||
|
_UpdateDrawState(fCurrentView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3342,6 +3346,12 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
link.Read<double>(&y);
|
link.Read<double>(&y);
|
||||||
|
|
||||||
picture->WriteTranslateBy(x, y);
|
picture->WriteTranslateBy(x, y);
|
||||||
|
|
||||||
|
BAffineTransform current =
|
||||||
|
fCurrentView->CurrentState()->Transform();
|
||||||
|
current.PreTranslateBy(x, y);
|
||||||
|
fCurrentView->CurrentState()->SetTransform(current);
|
||||||
|
_UpdateDrawState(fCurrentView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3352,6 +3362,12 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
link.Read<double>(&y);
|
link.Read<double>(&y);
|
||||||
|
|
||||||
picture->WriteScaleBy(x, y);
|
picture->WriteScaleBy(x, y);
|
||||||
|
|
||||||
|
BAffineTransform current =
|
||||||
|
fCurrentView->CurrentState()->Transform();
|
||||||
|
current.PreScaleBy(x, y);
|
||||||
|
fCurrentView->CurrentState()->SetTransform(current);
|
||||||
|
_UpdateDrawState(fCurrentView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3361,6 +3377,12 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
link.Read<double>(&angleRadians);
|
link.Read<double>(&angleRadians);
|
||||||
|
|
||||||
picture->WriteRotateBy(angleRadians);
|
picture->WriteRotateBy(angleRadians);
|
||||||
|
|
||||||
|
BAffineTransform current =
|
||||||
|
fCurrentView->CurrentState()->Transform();
|
||||||
|
current.PreRotateBy(angleRadians);
|
||||||
|
fCurrentView->CurrentState()->SetTransform(current);
|
||||||
|
_UpdateDrawState(fCurrentView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3375,7 +3397,11 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
|
|
||||||
case AS_VIEW_SET_FONT_STATE:
|
case AS_VIEW_SET_FONT_STATE:
|
||||||
{
|
{
|
||||||
picture->SetFontFromLink(link);
|
uint16 mask = fCurrentView->CurrentState()->ReadFontFromLink(link);
|
||||||
|
fWindow->GetDrawingEngine()->SetFont(
|
||||||
|
fCurrentView->CurrentState());
|
||||||
|
|
||||||
|
picture->WriteFontState(fCurrentView->CurrentState()->Font(), mask);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3498,6 +3524,12 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
link.Read<ViewStrokeLineInfo>(&info);
|
link.Read<ViewStrokeLineInfo>(&info);
|
||||||
|
|
||||||
picture->WriteStrokeLine(info.startPoint, info.endPoint);
|
picture->WriteStrokeLine(info.startPoint, info.endPoint);
|
||||||
|
|
||||||
|
BPoint penPos = info.endPoint;
|
||||||
|
const SimpleTransform transform =
|
||||||
|
fCurrentView->PenToScreenTransform();
|
||||||
|
transform.Apply(&info.endPoint);
|
||||||
|
fCurrentView->CurrentState()->SetPenLocation(penPos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3585,10 +3617,78 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
picture->WriteDrawString(info.location, string, info.stringLength,
|
picture->WriteDrawString(info.location, string, info.stringLength,
|
||||||
info.delta);
|
info.delta);
|
||||||
|
|
||||||
|
// We need to update the pen location
|
||||||
|
fCurrentView->PenToScreenTransform().Apply(&info.location);
|
||||||
|
BPoint penLocation = fWindow->GetDrawingEngine()->DrawStringDry(
|
||||||
|
string, info.stringLength, info.location, &info.delta);
|
||||||
|
|
||||||
|
fCurrentView->ScreenToPenTransform().Apply(&penLocation);
|
||||||
|
fCurrentView->CurrentState()->SetPenLocation(penLocation);
|
||||||
|
|
||||||
free(string);
|
free(string);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case AS_DRAW_STRING_WITH_OFFSETS:
|
||||||
|
{
|
||||||
|
int32 stringLength;
|
||||||
|
if (link.Read<int32>(&stringLength) != B_OK || stringLength <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int32 glyphCount;
|
||||||
|
if (link.Read<int32>(&glyphCount) != B_OK || glyphCount <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const ssize_t kMaxStackStringSize = 512;
|
||||||
|
char stackString[kMaxStackStringSize];
|
||||||
|
char* string = stackString;
|
||||||
|
BPoint stackLocations[kMaxStackStringSize];
|
||||||
|
BPoint* locations = stackLocations;
|
||||||
|
MemoryDeleter stringDeleter;
|
||||||
|
MemoryDeleter locationsDeleter;
|
||||||
|
if (stringLength >= kMaxStackStringSize) {
|
||||||
|
// NOTE: Careful, the + 1 is for termination!
|
||||||
|
string = (char*)malloc((stringLength + 1 + 63) / 64 * 64);
|
||||||
|
if (string == NULL)
|
||||||
|
break;
|
||||||
|
stringDeleter.SetTo(string);
|
||||||
|
}
|
||||||
|
if (glyphCount > kMaxStackStringSize) {
|
||||||
|
locations = (BPoint*)malloc(
|
||||||
|
((glyphCount * sizeof(BPoint)) + 63) / 64 * 64);
|
||||||
|
if (locations == NULL)
|
||||||
|
break;
|
||||||
|
locationsDeleter.SetTo(locations);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (link.Read(string, stringLength) != B_OK)
|
||||||
|
break;
|
||||||
|
// Count UTF8 glyphs and make sure we have enough locations
|
||||||
|
if ((int32)UTF8CountChars(string, stringLength) > glyphCount)
|
||||||
|
break;
|
||||||
|
if (link.Read(locations, glyphCount * sizeof(BPoint)) != B_OK)
|
||||||
|
break;
|
||||||
|
// Terminate the string
|
||||||
|
string[stringLength] = '\0';
|
||||||
|
|
||||||
|
const SimpleTransform transform =
|
||||||
|
fCurrentView->PenToScreenTransform();
|
||||||
|
for (int32 i = 0; i < glyphCount; i++)
|
||||||
|
transform.Apply(&locations[i]);
|
||||||
|
|
||||||
|
picture->WriteDrawString(string, stringLength, locations,
|
||||||
|
glyphCount);
|
||||||
|
|
||||||
|
// Update pen location
|
||||||
|
BPoint penLocation = fWindow->GetDrawingEngine()->DrawStringDry(
|
||||||
|
string, stringLength, locations);
|
||||||
|
|
||||||
|
fCurrentView->ScreenToPenTransform().Apply(&penLocation);
|
||||||
|
fCurrentView->CurrentState()->SetPenLocation(penLocation);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case AS_STROKE_SHAPE:
|
case AS_STROKE_SHAPE:
|
||||||
case AS_FILL_SHAPE:
|
case AS_FILL_SHAPE:
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user