FontDemo: Further cleanup
the strlen was used also in _AddShapes. Widen use of BString. Sorry for the noise!
This commit is contained in:
@@ -30,7 +30,6 @@ FontDemoView::FontDemoView(BRect rect)
|
|||||||
: BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
|
: BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
|
||||||
fBitmap(NULL),
|
fBitmap(NULL),
|
||||||
fBufferView(NULL),
|
fBufferView(NULL),
|
||||||
fString(NULL),
|
|
||||||
fFontSize(50.0),
|
fFontSize(50.0),
|
||||||
fSpacing(0.0),
|
fSpacing(0.0),
|
||||||
fOutLineLevel(0),
|
fOutLineLevel(0),
|
||||||
@@ -51,7 +50,6 @@ FontDemoView::FontDemoView(BRect rect)
|
|||||||
|
|
||||||
FontDemoView::~FontDemoView()
|
FontDemoView::~FontDemoView()
|
||||||
{
|
{
|
||||||
free(fString);
|
|
||||||
free(fShapes);
|
free(fShapes);
|
||||||
|
|
||||||
fBitmap->Lock();
|
fBitmap->Lock();
|
||||||
@@ -100,8 +98,7 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
|
|
||||||
view->SetFont(&fFont, B_FONT_ALL);
|
view->SetFont(&fFont, B_FONT_ALL);
|
||||||
|
|
||||||
BString tmpString(fString);
|
const size_t size = fString.CountChars();
|
||||||
const size_t size = tmpString.CountChars();
|
|
||||||
BRect boundBoxes[size];
|
BRect boundBoxes[size];
|
||||||
|
|
||||||
if (OutLineLevel())
|
if (OutLineLevel())
|
||||||
@@ -118,8 +115,8 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
escapeDeltas[j].space = 0.0f;
|
escapeDeltas[j].space = 0.0f;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
fFont.GetEdges(fString, size, edgeInfo);
|
fFont.GetEdges(fString.String(), size, edgeInfo);
|
||||||
fFont.GetEscapements(fString, size, /*escapeDeltas,*/ escapementArray);
|
fFont.GetEscapements(fString.String(), size, /*escapeDeltas,*/ escapementArray);
|
||||||
|
|
||||||
font_height fh;
|
font_height fh;
|
||||||
fFont.GetHeight(&fh);
|
fFont.GetHeight(&fh);
|
||||||
@@ -162,7 +159,7 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
view->SetHighColor(0, 0, 0);
|
view->SetHighColor(0, 0, 0);
|
||||||
view->SetDrawingMode(fDrawingMode);
|
view->SetDrawingMode(fDrawingMode);
|
||||||
int32 charLength;
|
int32 charLength;
|
||||||
const char* charAt = tmpString.CharAt(i, &charLength);
|
const char* charAt = fString.CharAt(i, &charLength);
|
||||||
view->DrawString(charAt, charLength,
|
view->DrawString(charAt, charLength,
|
||||||
BPoint(xCoordArray[i], yCoordArray[i]));
|
BPoint(xCoordArray[i], yCoordArray[i]));
|
||||||
}
|
}
|
||||||
@@ -192,7 +189,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case TEXT_CHANGED_MSG:
|
case TEXT_CHANGED_MSG:
|
||||||
{
|
{
|
||||||
const char* text = NULL;
|
BString text;
|
||||||
if (msg->FindString("_text", &text) == B_OK) {
|
if (msg->FindString("_text", &text) == B_OK) {
|
||||||
SetString(text);
|
SetString(text);
|
||||||
Invalidate(/*&fBoxRegion*/);
|
Invalidate(/*&fBoxRegion*/);
|
||||||
@@ -358,16 +355,15 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FontDemoView::SetString(const char* string)
|
FontDemoView::SetString(BString string)
|
||||||
{
|
{
|
||||||
free(fString);
|
fString = string;
|
||||||
fString = strdup(string);
|
|
||||||
free(fShapes);
|
free(fShapes);
|
||||||
_AddShapes(fString);
|
_AddShapes(fString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
BString
|
||||||
FontDemoView::String() const
|
FontDemoView::String() const
|
||||||
{
|
{
|
||||||
return fString;
|
return fString;
|
||||||
@@ -424,10 +420,10 @@ FontDemoView::SetOutlineLevel(int8 outline)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FontDemoView::_AddShapes(const char* string)
|
FontDemoView::_AddShapes(BString string)
|
||||||
{
|
{
|
||||||
const size_t size = strlen(string);
|
const size_t size = string.CountChars();
|
||||||
fShapes = (BShape**)malloc(sizeof(BShape*)*size);
|
fShapes = (BShape**)malloc(sizeof(BShape*) * size);
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
fShapes[i] = new BShape();
|
fShapes[i] = new BShape();
|
||||||
@@ -460,5 +456,4 @@ FontDemoView::_NewBitmap(BRect rect)
|
|||||||
delete fBitmap;
|
delete fBitmap;
|
||||||
fBitmap = NULL;
|
fBitmap = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
class BShape;
|
class BShape;
|
||||||
class BBitmap;
|
class BBitmap;
|
||||||
@@ -37,8 +38,8 @@ class FontDemoView : public BView {
|
|||||||
void SetFontRotation(float rotation);
|
void SetFontRotation(float rotation);
|
||||||
const float Rotation() const { return fFont.Rotation(); }
|
const float Rotation() const { return fFont.Rotation(); }
|
||||||
|
|
||||||
void SetString(const char* string);
|
void SetString(BString string);
|
||||||
const char* String() const;
|
BString String() const;
|
||||||
|
|
||||||
void SetAntialiasing(bool state);
|
void SetAntialiasing(bool state);
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ class FontDemoView : public BView {
|
|||||||
const int8 OutLineLevel() const { return fOutLineLevel; }
|
const int8 OutLineLevel() const { return fOutLineLevel; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _AddShapes(const char* string);
|
void _AddShapes(BString string);
|
||||||
void _DrawView(BView* view);
|
void _DrawView(BView* view);
|
||||||
|
|
||||||
BView* _GetView(BRect rect);
|
BView* _GetView(BRect rect);
|
||||||
@@ -58,7 +59,7 @@ class FontDemoView : public BView {
|
|||||||
BBitmap* fBitmap;
|
BBitmap* fBitmap;
|
||||||
BView* fBufferView;
|
BView* fBufferView;
|
||||||
|
|
||||||
char* fString;
|
BString fString;
|
||||||
float fFontSize;
|
float fFontSize;
|
||||||
float fSpacing;
|
float fSpacing;
|
||||||
int8 fOutLineLevel;
|
int8 fOutLineLevel;
|
||||||
|
|||||||
Reference in New Issue
Block a user