* Added LinkReceiver methods that return the length of the string.
* AS_GET_STRING_WIDTHS now uses this method to send the strings to the app_server; ie. it no longer sends the whole strings, and it saves sending the string length separately. * BFont::StringWidth() will now always return 0.0f in case of an error (instead of some random value) * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16525 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2005, Haiku.
|
||||
* Copyright 2001-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -32,13 +32,12 @@ class LinkReceiver {
|
||||
int32 Code() const;
|
||||
|
||||
virtual status_t Read(void *data, ssize_t size);
|
||||
status_t ReadString(char **string);
|
||||
status_t ReadString(BString& string);
|
||||
status_t ReadString(char** _string, size_t* _length = NULL);
|
||||
status_t ReadString(BString& string, size_t* _length = NULL);
|
||||
status_t ReadString(char *buffer, size_t bufferSize);
|
||||
|
||||
template <class Type> status_t Read(Type *data)
|
||||
{
|
||||
return Read(data, sizeof(Type));
|
||||
}
|
||||
{ return Read(data, sizeof(Type)); }
|
||||
|
||||
protected:
|
||||
virtual status_t ReadFromPort(bigtime_t timeout);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2005, Haiku.
|
||||
* Copyright 2001-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -60,8 +60,8 @@ class ServerLink {
|
||||
bool NeedsReply() const;
|
||||
status_t Read(void *data, ssize_t size);
|
||||
status_t ReadString(char *buffer, size_t bufferSize);
|
||||
status_t ReadString(BString& string);
|
||||
status_t ReadString(char **string);
|
||||
status_t ReadString(BString& string, size_t* _length = NULL);
|
||||
status_t ReadString(char** _string, size_t* _length = NULL);
|
||||
status_t ReadRegion(BRegion *region);
|
||||
status_t ReadShape(BShape *shape);
|
||||
template <class Type> status_t Read(Type *data);
|
||||
@@ -173,15 +173,15 @@ ServerLink::ReadString(char *buffer, size_t bufferSize)
|
||||
}
|
||||
|
||||
inline status_t
|
||||
ServerLink::ReadString(BString& string)
|
||||
ServerLink::ReadString(BString& string, size_t* _length)
|
||||
{
|
||||
return fReceiver->ReadString(string);
|
||||
return fReceiver->ReadString(string, _length);
|
||||
}
|
||||
|
||||
inline status_t
|
||||
ServerLink::ReadString(char **string)
|
||||
ServerLink::ReadString(char** _string, size_t* _length)
|
||||
{
|
||||
return fReceiver->ReadString(string);
|
||||
return fReceiver->ReadString(_string, _length);
|
||||
}
|
||||
|
||||
template <class Type> status_t
|
||||
|
||||
@@ -984,9 +984,9 @@ float
|
||||
BFont::StringWidth(const char *string, int32 length) const
|
||||
{
|
||||
if (!string || length < 1)
|
||||
return 0.0;
|
||||
return 0.0f;
|
||||
|
||||
float width;
|
||||
float width = 0.0f;
|
||||
GetStringWidths(&string, &length, 1, &width);
|
||||
|
||||
return width;
|
||||
@@ -1011,13 +1011,12 @@ BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[],
|
||||
// TODO: all strings into a single array???
|
||||
// we do have a maximum message length, and it could be easily touched here...
|
||||
for (int32 i = 0; i < numStrings; i++) {
|
||||
link.Attach<int32>(lengthArray[i]);
|
||||
link.AttachString(stringArray[i]);
|
||||
link.AttachString(stringArray[i], lengthArray[i]);
|
||||
}
|
||||
|
||||
int32 code;
|
||||
if (link.FlushWithReply(code) != B_OK
|
||||
|| code != B_OK)
|
||||
status_t status;
|
||||
if (link.FlushWithReply(status) != B_OK
|
||||
|| status != B_OK)
|
||||
return;
|
||||
|
||||
link.Read(widthArray, sizeof(float) * numStrings);
|
||||
@@ -1046,8 +1045,8 @@ BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *
|
||||
link.Attach<float>(fRotation);
|
||||
link.Attach<uint32>(fFlags);
|
||||
|
||||
link.Attach<float>(delta ? delta->nonspace : 0.0);
|
||||
link.Attach<float>(delta ? delta->space : 0.0);
|
||||
link.Attach<float>(delta ? delta->nonspace : 0.0f);
|
||||
link.Attach<float>(delta ? delta->space : 0.0f);
|
||||
link.Attach<int32>(numChars);
|
||||
|
||||
// TODO: Should we not worry about the port capacity here?!?
|
||||
|
||||
@@ -1401,23 +1401,22 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
link.Read<float>(&size);
|
||||
link.Read<uint8>(&spacing);
|
||||
int32 numStrings;
|
||||
link.Read<int32>(&numStrings);
|
||||
if (link.Read<int32>(&numStrings) != B_OK) {
|
||||
// this results in a B_BAD_VALUE return
|
||||
numStrings = 0;
|
||||
size = 0.0f;
|
||||
}
|
||||
|
||||
float widthArray[numStrings];
|
||||
int32 lengthArray[numStrings];
|
||||
char *stringArray[numStrings];
|
||||
for (int32 i = 0; i < numStrings; i++) {
|
||||
// TODO: the length is actually encoded twice here
|
||||
// It would be nicer to only send as much from the string as needed
|
||||
link.Read<int32>(&lengthArray[i]);
|
||||
link.ReadString(&stringArray[i]);
|
||||
link.ReadString(&stringArray[i], (size_t *)&lengthArray[i]);
|
||||
}
|
||||
|
||||
ServerFont font;
|
||||
|
||||
if (font.SetFamilyAndStyle(family, style) == B_OK
|
||||
&& size > 0) {
|
||||
|
||||
if (font.SetFamilyAndStyle(family, style) == B_OK && size > 0) {
|
||||
font.SetSize(size);
|
||||
font.SetSpacing(spacing);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user