BPicture: fix BeOS flattened format compatibility

- BeOS store strings with `int32` size prefix.

- Corrected `B_PIC_DRAW_STRING` field order to match BeOS.

Part of #1133.

Change-Id: I354fbf3e8a093ee21a87a6400a036751b442955b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9307
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Stephan Aßmus <[email protected]>
This commit is contained in:
X512
2025-05-27 12:56:03 +00:00
committed by waddlesplash
parent e88cfea6cf
commit c5f7786d06
2 changed files with 29 additions and 23 deletions
+11 -9
View File
@@ -496,12 +496,10 @@ PictureDataWriter::WriteDrawString(const BPoint& where, const char* string,
EndOp();
BeginOp(B_PIC_DRAW_STRING);
Write<int32>(length);
WriteData(string, length);
Write<float>(escapement.space);
Write<float>(escapement.nonspace);
//WriteData(string, length + 1);
// TODO: is string 0 terminated? why is length given?
WriteData(string, length);
Write<uint8>(0);
EndOp();
} catch (status_t& status) {
return status;
@@ -521,8 +519,8 @@ PictureDataWriter::WriteDrawString(const char* string,
for (int32 i = 0; i < locationCount; i++) {
Write<BPoint>(locations[i]);
}
Write<int32>(length);
WriteData(string, length);
Write<uint8>(0);
EndOp();
} catch (status_t& status) {
return status;
@@ -734,8 +732,10 @@ PictureDataWriter::WriteSetFontFamily(const font_family family)
{
try {
BeginOp(B_PIC_SET_FONT_FAMILY);
WriteData(family, strlen(family));
Write<uint8>(0);
// BeOS writes string size including terminating null character for some reason.
uint32 length = strlen(family) + 1;
Write<uint32>(length);
WriteData(family, length);
EndOp();
} catch (status_t& status) {
return status;
@@ -750,8 +750,10 @@ PictureDataWriter::WriteSetFontStyle(const font_style style)
{
try {
BeginOp(B_PIC_SET_FONT_STYLE);
WriteData(style, strlen(style));
Write<uint8>(0);
// BeOS writes string size including terminating null character for some reason.
uint32 length = strlen(style) + 1;
Write<uint32>(length);
WriteData(style, length);
EndOp();
} catch (status_t& status) {
return status;
+18 -14
View File
@@ -1202,18 +1202,19 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
case B_PIC_DRAW_STRING:
{
const int32* length;
const char* string;
const float* escapementSpace;
const float* escapementNonSpace;
const char* string;
size_t length;
if (callbacks.draw_string == NULL
|| !reader.Get(length)
|| !reader.Get(string, *length)
|| !reader.Get(escapementSpace)
|| !reader.Get(escapementNonSpace)
|| !reader.GetRemaining(string, length)) {
|| !reader.Get(escapementNonSpace)) {
break;
}
callbacks.draw_string(userData, string, length,
callbacks.draw_string(userData, string, *length,
*escapementSpace, *escapementNonSpace);
break;
}
@@ -1222,16 +1223,17 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
{
const uint32* pointCount;
const BPoint* pointList;
const int32* length;
const char* string;
size_t length;
if (callbacks.draw_string_locations == NULL
|| !reader.Get(pointCount)
|| !reader.Get(pointList, *pointCount)
|| !reader.GetRemaining(string, length)) {
|| !reader.Get(length)
|| !reader.Get(string, *length)) {
break;
}
callbacks.draw_string_locations(userData, string, length,
callbacks.draw_string_locations(userData, string, *length,
pointList, *pointCount);
break;
}
@@ -1454,27 +1456,29 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
case B_PIC_SET_FONT_FAMILY:
{
const int32* length;
const char* family;
size_t length;
if (callbacks.set_font_family == NULL
|| !reader.GetRemaining(family, length)) {
|| !reader.Get(length)
|| !reader.Get(family, *length)) {
break;
}
callbacks.set_font_family(userData, family, length);
callbacks.set_font_family(userData, family, *length);
break;
}
case B_PIC_SET_FONT_STYLE:
{
const int32* length;
const char* style;
size_t length;
if (callbacks.set_font_style == NULL
|| !reader.GetRemaining(style, length)) {
|| !reader.Get(length)
|| !reader.Get(style, *length)) {
break;
}
callbacks.set_font_style(userData, style, length);
callbacks.set_font_style(userData, style, *length);
break;
}