52 m_underlineStyle(false),
131 std::string::const_iterator cur;
132 if (text.size() == 0)
return 0;
133 if (x <= 0)
return 0;
140 while(cur != text.end()) {
141 buff = std::string(text.begin(), cur);
168 const uint8_t newline_utf8 =
'\n';
174 std::vector<SDL_Surface*> lines;
175 std::string::const_iterator it = text.begin();
177 int32_t render_width = 0, render_height = 0;
181 while( codepoint != newline && it != text.end() )
184 if( codepoint != newline )
189 if (text_surface->w > render_width) {
190 render_width = text_surface->w;
192 lines.push_back(text_surface);
193 }
while (it != text.end());
196 SDL_Surface* final_surface = SDL_CreateRGBSurface(0,
197 render_width,render_height,32,
199 if (!final_surface) {
200 throw SDLException(std::string(
"CreateRGBSurface failed: ") + SDL_GetError());
202 SDL_FillRect(final_surface, 0, 0x00000000);
204 for (std::vector<SDL_Surface*>::iterator i = lines.begin(); i != lines.end(); ++i) {
205 SDL_Rect dst_rect = { 0, 0, 0, 0 };
210 SDL_SetSurfaceBlendMode(*i, SDL_BLENDMODE_NONE);
211 SDL_BlitSurface(*i, 0, final_surface, &dst_rect);
223 const uint8_t newline_utf8 =
'\n';
226 if (render_width <= 0 || text.empty()) {
231 std::string::const_iterator pos = text.begin();
232 std::list<std::pair<size_t,std::string::const_iterator> > break_pos;
233 bool firstLine =
true;
235 while( pos != text.end())
244 bool haveNewLine =
false;
245 while(
getWidth(line) < render_width && pos != text.end() )
248 if (codepoint == whitespace && !line.empty())
249 break_pos.push_back( std::make_pair(line.length(),pos) );
251 if( codepoint != newline )
255 if( codepoint == newline ) {
265 if( pos == text.end() )
268 if( break_pos.empty() ) {
272 if(
utf8::distance(line.begin(),line.end()) <= 1 && line !=
"\n") {
287 line = line.substr(0,break_pos.back().first);
288 pos = break_pos.back().second;
292 if( !line.empty() ) {
virtual bool isItalicStyle() const
Checks if italic style is used.
virtual void setUnderlineStyle(bool style)
Sets the use of underline style.
u32bit_iterator utf8to32(octet_iterator start, octet_iterator end, u32bit_iterator result)
virtual bool isUnderlineStyle() const
Checks if underline style is used.
virtual bool isAntiAlias() const
Checks if anti aliasing is used.
uint32_t next(octet_iterator &it, octet_iterator end)
virtual bool isStrikethroughStyle() const
Checks if strikethrough style is used.
void invalidateCachedText()
Invalidates all cached text images.
Image * getAsImageMultiline(const std::string &text)
Gets given text as Image.
virtual void setAntiAlias(bool antiAlias)
Sets the use of anti aliasing.
virtual void setStrikethroughStyle(bool style)
Sets the use of strikethrough style.
SDL_Color getColor() const
Get the color the text was rendered in.
virtual void setDynamicColoring(bool coloring)
static RenderBackend * instance()
Image * getRenderedText(FontBase *fontbase, const std::string &text)
Get a string image.
virtual int32_t getStringIndexAt(const std::string &text, int32_t x) const
bool is_valid(octet_iterator start, octet_iterator end)
void setRowSpacing(int32_t spacing)
Sets the spacing between rows in pixels.
virtual void setItalicStyle(bool style)
Sets the use of italic style.
virtual void setBoldStyle(bool style)
Sets the use of bold style.
void addRenderedText(FontBase *fontbase, const std::string &text, Image *image)
Add a string image.
virtual int32_t getHeight() const =0
gets height of this font
Image * getAsImage(const std::string &text)
Gets given text as Image The rsulting image is pooled, so it's not that time critical.
void setGlyphSpacing(int32_t spacing)
Sets the spacing between letters in pixels.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
std::string splitTextToWidth(const std::string &text, int32_t render_width)
virtual Image * createImage(IResourceLoader *loader=0)=0
virtual SDL_Surface * renderString(const std::string &text)=0
virtual int32_t getWidth(const std::string &text) const =0
gets width of given text
virtual bool isBoldStyle() const
Checks if bold style is used.
int32_t getGlyphSpacing() const
Gets the spacing between letters in pixels.
int32_t getRowSpacing() const
Gets the spacing between rows in pixels.
octet_iterator append(uint32_t cp, octet_iterator result)
The library API - functions intended to be called by the users.
virtual bool isDynamicColoring() const