From 2ed942c199a7fcc5b119566d5626adf5be3f251b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Feb 2006 13:09:37 +0000 Subject: [PATCH] * 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 --- headers/private/app/LinkReceiver.h | 11 +++++------ headers/private/app/ServerLink.h | 14 +++++++------- src/kits/interface/Font.cpp | 17 ++++++++--------- src/servers/app/ServerApp.cpp | 15 +++++++-------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/headers/private/app/LinkReceiver.h b/headers/private/app/LinkReceiver.h index fc2f275945..b2a804d205 100644 --- a/headers/private/app/LinkReceiver.h +++ b/headers/private/app/LinkReceiver.h @@ -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 status_t Read(Type *data) - { - return Read(data, sizeof(Type)); - } + { return Read(data, sizeof(Type)); } protected: virtual status_t ReadFromPort(bigtime_t timeout); diff --git a/headers/private/app/ServerLink.h b/headers/private/app/ServerLink.h index 6e7ee68c6e..f564bf255c 100644 --- a/headers/private/app/ServerLink.h +++ b/headers/private/app/ServerLink.h @@ -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 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 status_t diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 95d6a1eed9..47af8e8884 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -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(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(fRotation); link.Attach(fFlags); - link.Attach(delta ? delta->nonspace : 0.0); - link.Attach(delta ? delta->space : 0.0); + link.Attach(delta ? delta->nonspace : 0.0f); + link.Attach(delta ? delta->space : 0.0f); link.Attach(numChars); // TODO: Should we not worry about the port capacity here?!? diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 9e270dbec2..9402d6d8c9 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1401,23 +1401,22 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(&size); link.Read(&spacing); int32 numStrings; - link.Read(&numStrings); + if (link.Read(&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(&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);