86 std::string::const_iterator cur;
87 if (text.size() == 0)
return 0;
95 while(cur != text.end()) {
96 buff = std::string(text.begin(), cur);
123 const uint8_t newline_utf8 =
'\n';
129 std::vector<SDL_Surface*> lines;
130 std::string::const_iterator it = text.begin();
132 int32_t render_width = 0, render_height = 0;
136 while( codepoint != newline && it != text.end() )
139 if( codepoint != newline )
144 if (text_surface->w > render_width) {
145 render_width = text_surface->w;
147 lines.push_back(text_surface);
148 }
while (it != text.end());
151 SDL_Surface* final_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
152 render_width,render_height,32,
154 if (!final_surface) {
155 throw SDLException(std::string(
"CreateRGBSurface failed: ") + SDL_GetError());
157 SDL_FillRect(final_surface, 0, 0x00000000);
159 for (std::vector<SDL_Surface*>::iterator i = lines.begin(); i != lines.end(); ++i) {
160 SDL_Rect dst_rect = { 0, 0, 0, 0 };
163 SDL_SetAlpha(*i,0,SDL_ALPHA_OPAQUE);
164 SDL_BlitSurface(*i,0,final_surface,&dst_rect);
176 const uint8_t newline_utf8 =
'\n';
179 if (render_width <= 0 || text.empty()) {
184 std::string::const_iterator pos = text.begin();
185 std::list<std::pair<size_t,std::string::const_iterator> > break_pos;
186 bool firstLine =
true;
188 while( pos != text.end())
197 bool haveNewLine =
false;
198 while(
getWidth(line) < render_width && pos != text.end() )
201 if (codepoint == whitespace && !line.empty())
202 break_pos.push_back( std::make_pair(line.length(),pos) );
204 if( codepoint != newline )
208 if( codepoint == newline ) {
218 if( pos == text.end() )
221 if( break_pos.empty() ) {
225 if(
utf8::distance(line.begin(),line.end()) <= 1 && line !=
"\n") {
240 line = line.substr(0,break_pos.back().first);
241 pos = break_pos.back().second;
245 if( !line.empty() ) {
int32_t getGlyphSpacing() const
Gets the spacing between letters in pixels.
u32bit_iterator utf8to32(octet_iterator start, octet_iterator end, u32bit_iterator result)
uint32_t next(octet_iterator &it, octet_iterator end)
void invalidateCachedText()
Invalidates all cached text images.
Image * getAsImageMultiline(const std::string &text)
Gets given text as Image.
void setAntiAlias(bool antiAlias)
Sets the use of anti aliasing.
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.
void addRenderedText(FontBase *fontbase, const std::string &text, Image *image)
Add a string image.
int32_t getRowSpacing() const
Gets the spacing between rows in pixels.
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.
bool isAntiAlias()
Checks if anti aliasing is used.
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
SDL_Color getColor() const
Get the color the text was rendered in.
virtual int32_t getWidth(const std::string &text) const =0
gets width of given text
octet_iterator append(uint32_t cp, octet_iterator result)