From ae3bc8673d79edecb8fcb918d83db011535b0955 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Sun, 18 Jun 2006 19:09:36 +0000 Subject: hopefully fix frequently segfaults --- lib/gdi/font.cpp | 21 +++++++++++---------- lib/gdi/font.h | 2 +- lib/gdi/grc.cpp | 5 +++-- lib/gdi/grc.h | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib/gdi') diff --git a/lib/gdi/font.cpp b/lib/gdi/font.cpp index 2ff5fbf7..f7c1bca5 100644 --- a/lib/gdi/font.cpp +++ b/lib/gdi/font.cpp @@ -443,7 +443,7 @@ void eTextPara::setFont(Font *fnt, Font *replacement) void shape (std::vector &string, const std::vector &text); -int eTextPara::renderString(const std::string &string, int rflags) +int eTextPara::renderString(const char *string, int rflags) { singleLock s(ftlock); @@ -467,11 +467,12 @@ int eTextPara::renderString(const std::string &string, int rflags) } std::vector uc_string, uc_visual; - uc_string.reserve(string.length()); + if (string) + uc_string.reserve(strlen(string)); - std::string::const_iterator p(string.begin()); + const char *p = string; - while(p != string.end()) + while(p) { unsigned int unicode=(unsigned char)*p++; @@ -481,28 +482,28 @@ int eTextPara::renderString(const std::string &string, int rflags) { unicode&=0x1F; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; } else if ((unicode & 0xF0)==0xE0) // three bytes { unicode&=0x0F; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; } else if ((unicode & 0xF8)==0xF0) // four bytes { unicode&=0x07; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; unicode<<=6; - if (p != string.end()) + if (p) unicode|=(*p++)&0x3F; } } diff --git a/lib/gdi/font.h b/lib/gdi/font.h index b8983914..6cc238d7 100644 --- a/lib/gdi/font.h +++ b/lib/gdi/font.h @@ -126,7 +126,7 @@ public: static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); } void setFont(const gFont *font); - int renderString(const std::string &string, int flags=0); + int renderString(const char *string, int flags=0); void clear(); diff --git a/lib/gdi/grc.cpp b/lib/gdi/grc.cpp index 274d221b..ef75aace 100644 --- a/lib/gdi/grc.cpp +++ b/lib/gdi/grc.cpp @@ -237,7 +237,7 @@ void gPainter::renderText(const eRect &pos, const std::string &string, int flags o.dc = m_dc.grabRef(); o.parm.renderText = new gOpcode::para::prenderText; o.parm.renderText->area = pos; - o.parm.renderText->text = string; + o.parm.renderText->text = string.empty()?0:strdup(string.c_str()); o.parm.renderText->flags = flags; m_rc->submit(o); } @@ -539,7 +539,8 @@ void gDC::exec(gOpcode *o) assert(m_current_font); para->setFont(m_current_font); para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0); - + if (o->parm.renderText->text) + free(o->parm.renderText->text); if (flags & gPainter::RT_HALIGN_RIGHT) para->realign(eTextPara::dirRight); else if (flags & gPainter::RT_HALIGN_CENTER) diff --git a/lib/gdi/grc.h b/lib/gdi/grc.h index 58371e79..11355504 100644 --- a/lib/gdi/grc.h +++ b/lib/gdi/grc.h @@ -78,7 +78,7 @@ struct gOpcode struct prenderText { eRect area; - std::string text; + char *text; int flags; } *renderText; -- cgit v1.2.3