From a9daf3d9110b857f16e84b3ebbaa7fe6934abdb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 15 Mar 2010 15:08:07 +0000 Subject: [PATCH] Improved the DrawString() method that takes offsets per glyph by making the client provide the array size. Added version that doesn't take a string length for convenience. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35866 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/View.h | 6 +++++- src/kits/interface/View.cpp | 20 ++++++++++++++----- .../servers/app/draw_string_offsets/main.cpp | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index 19a0e3e4f8..c6d0cc8a13 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -433,8 +433,12 @@ public: void DrawString(const char* string, int32 length, BPoint location, escapement_delta* delta = 0L); + void DrawString(const char* string, + const BPoint* locations, + int32 locationCount); void DrawString(const char* string, int32 length, - const BPoint* locations); + const BPoint* locations, + int32 locationCount); virtual void SetFont(const BFont* font, uint32 mask = B_FONT_ALL); diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index b051f8704f..ec599c188b 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -45,7 +45,6 @@ #include #include -#include #include #include #include @@ -2571,7 +2570,19 @@ BView::DrawString(const char* string, int32 length, BPoint location, void -BView::DrawString(const char* string, int32 length, const BPoint* locations) +BView::DrawString(const char* string, const BPoint* locations, + int32 locationCount) +{ + if (string == NULL) + return; + + DrawString(string, strlen(string), locations, locationCount); +} + + +void +BView::DrawString(const char* string, int32 length, const BPoint* locations, + int32 locationCount) { if (fOwner == NULL || string == NULL || length < 1 || locations == NULL) return; @@ -2580,11 +2591,10 @@ BView::DrawString(const char* string, int32 length, const BPoint* locations) fOwner->fLink->StartMessage(AS_DRAW_STRING_WITH_OFFSETS); - int32 glyphCount = UTF8CountChars(string, length); fOwner->fLink->Attach(length); - fOwner->fLink->Attach(glyphCount); + fOwner->fLink->Attach(locationCount); fOwner->fLink->Attach(string, length); - fOwner->fLink->Attach(locations, glyphCount * sizeof(BPoint)); + fOwner->fLink->Attach(locations, locationCount * sizeof(BPoint)); _FlushIfNotInTransaction(); diff --git a/src/tests/servers/app/draw_string_offsets/main.cpp b/src/tests/servers/app/draw_string_offsets/main.cpp index 37269a974e..04cdeebd4d 100644 --- a/src/tests/servers/app/draw_string_offsets/main.cpp +++ b/src/tests/servers/app/draw_string_offsets/main.cpp @@ -43,7 +43,7 @@ TestView::Draw(BRect updateRect) offsets[4].x = 30; offsets[4].y = 10; - DrawString("Hello", strlen("Hello"), offsets); + DrawString("Hello", offsets, 5); }