diff options
| author | Philippe Saint-Pierre <stpere@gmail.com> | 2012-07-21 12:58:05 -0400 |
|---|---|---|
| committer | Philippe Saint-Pierre <stpere@gmail.com> | 2012-07-21 12:58:05 -0400 |
| commit | 5cf20610e113bcf3bddddf323fdf348ac283c4be (patch) | |
| tree | d67f191f9e89868960cb1341aefd75799e66ac89 | |
| parent | c5e8e32acd64dbbf41b67aee6dd7badb66c1ca7b (diff) | |
FontDemo: Further cleanuphrev44375
the strlen was used also in _AddShapes. Widen use of BString.
Sorry for the noise!
| -rw-r--r-- | src/apps/fontdemo/FontDemoView.cpp | 29 | ||||
| -rw-r--r-- | src/apps/fontdemo/FontDemoView.h | 9 |
2 files changed, 17 insertions, 21 deletions
diff --git a/src/apps/fontdemo/FontDemoView.cpp b/src/apps/fontdemo/FontDemoView.cpp index 5294eca5ff..af4205ed3d 100644 --- a/src/apps/fontdemo/FontDemoView.cpp +++ b/src/apps/fontdemo/FontDemoView.cpp @@ -30,7 +30,6 @@ FontDemoView::FontDemoView(BRect rect) : BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS), fBitmap(NULL), fBufferView(NULL), - fString(NULL), fFontSize(50.0), fSpacing(0.0), fOutLineLevel(0), @@ -51,7 +50,6 @@ FontDemoView::FontDemoView(BRect rect) FontDemoView::~FontDemoView() { - free(fString); free(fShapes); fBitmap->Lock(); @@ -100,8 +98,7 @@ FontDemoView::_DrawView(BView* view) view->SetFont(&fFont, B_FONT_ALL); - BString tmpString(fString); - const size_t size = tmpString.CountChars(); + const size_t size = fString.CountChars(); BRect boundBoxes[size]; if (OutLineLevel()) @@ -118,8 +115,8 @@ FontDemoView::_DrawView(BView* view) escapeDeltas[j].space = 0.0f; } */ - fFont.GetEdges(fString, size, edgeInfo); - fFont.GetEscapements(fString, size, /*escapeDeltas,*/ escapementArray); + fFont.GetEdges(fString.String(), size, edgeInfo); + fFont.GetEscapements(fString.String(), size, /*escapeDeltas,*/ escapementArray); font_height fh; fFont.GetHeight(&fh); @@ -162,7 +159,7 @@ FontDemoView::_DrawView(BView* view) view->SetHighColor(0, 0, 0); view->SetDrawingMode(fDrawingMode); int32 charLength; - const char* charAt = tmpString.CharAt(i, &charLength); + const char* charAt = fString.CharAt(i, &charLength); view->DrawString(charAt, charLength, BPoint(xCoordArray[i], yCoordArray[i])); } @@ -192,7 +189,7 @@ FontDemoView::MessageReceived(BMessage* msg) switch (msg->what) { case TEXT_CHANGED_MSG: { - const char* text = NULL; + BString text; if (msg->FindString("_text", &text) == B_OK) { SetString(text); Invalidate(/*&fBoxRegion*/); @@ -358,16 +355,15 @@ FontDemoView::MessageReceived(BMessage* msg) void -FontDemoView::SetString(const char* string) +FontDemoView::SetString(BString string) { - free(fString); - fString = strdup(string); + fString = string; free(fShapes); _AddShapes(fString); } -const char* +BString FontDemoView::String() const { return fString; @@ -424,10 +420,10 @@ FontDemoView::SetOutlineLevel(int8 outline) void -FontDemoView::_AddShapes(const char* string) +FontDemoView::_AddShapes(BString string) { - const size_t size = strlen(string); - fShapes = (BShape**)malloc(sizeof(BShape*)*size); + const size_t size = string.CountChars(); + fShapes = (BShape**)malloc(sizeof(BShape*) * size); for (size_t i = 0; i < size; i++) { fShapes[i] = new BShape(); @@ -460,5 +456,4 @@ FontDemoView::_NewBitmap(BRect rect) delete fBitmap; fBitmap = NULL; } -} - +}
\ No newline at end of file diff --git a/src/apps/fontdemo/FontDemoView.h b/src/apps/fontdemo/FontDemoView.h index 66d3daca9e..23b1395eff 100644 --- a/src/apps/fontdemo/FontDemoView.h +++ b/src/apps/fontdemo/FontDemoView.h @@ -11,6 +11,7 @@ #include <View.h> #include <Region.h> +#include <String.h> class BShape; class BBitmap; @@ -37,8 +38,8 @@ class FontDemoView : public BView { void SetFontRotation(float rotation); const float Rotation() const { return fFont.Rotation(); } - void SetString(const char* string); - const char* String() const; + void SetString(BString string); + BString String() const; void SetAntialiasing(bool state); @@ -49,7 +50,7 @@ class FontDemoView : public BView { const int8 OutLineLevel() const { return fOutLineLevel; } private: - void _AddShapes(const char* string); + void _AddShapes(BString string); void _DrawView(BView* view); BView* _GetView(BRect rect); @@ -58,7 +59,7 @@ class FontDemoView : public BView { BBitmap* fBitmap; BView* fBufferView; - char* fString; + BString fString; float fFontSize; float fSpacing; int8 fOutLineLevel; |
