1 #include <lib/gdi/font.h>
12 #error "no BYTE_ORDER defined!"
15 // use this for init Freetype...
17 #include FT_FREETYPE_H
18 #define FTC_Image_Cache_New(a,b) FTC_ImageCache_New(a,b)
19 #define FTC_Image_Cache_Lookup(a,b,c,d) FTC_ImageCache_Lookup(a,b,c,d,NULL)
20 #define FTC_SBit_Cache_New(a,b) FTC_SBitCache_New(a,b)
21 #define FTC_SBit_Cache_Lookup(a,b,c,d) FTC_SBitCache_Lookup(a,b,c,d,NULL)
23 #include <lib/base/eerror.h>
24 #include <lib/gdi/lcd.h>
25 #include <lib/gdi/grc.h>
26 #include <lib/base/elock.h>
27 #include <lib/base/init.h>
28 #include <lib/base/init_num.h>
30 #include <fribidi/fribidi.h>
34 fontRenderClass *fontRenderClass::instance;
36 static pthread_mutex_t ftlock=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
38 struct fntColorCacheKey
41 fntColorCacheKey(const gRGB &start, const gRGB &end)
42 : start(start), end(end)
45 bool operator <(const fntColorCacheKey &c) const
49 else if (start == c.start)
55 std::map<fntColorCacheKey,gLookup> colorcache;
57 static gLookup &getColor(const gPalette &pal, const gRGB &start, const gRGB &end)
59 fntColorCacheKey key(start, end);
60 std::map<fntColorCacheKey,gLookup>::iterator i=colorcache.find(key);
61 if (i != colorcache.end())
63 gLookup &n=colorcache.insert(std::pair<fntColorCacheKey,gLookup>(key,gLookup())).first->second;
64 // eDebug("[FONT] creating new font color cache entry %02x%02x%02x%02x .. %02x%02x%02x%02x", start.a, start.r, start.g, start.b,
65 // end.a, end.r, end.g, end.b);
66 n.build(16, pal, start, end);
67 // for (int i=0; i<16; i++)
68 // eDebugNoNewLine("%02x|%02x%02x%02x%02x ", (int)n.lookup[i], pal.data[n.lookup[i]].a, pal.data[n.lookup[i]].r, pal.data[n.lookup[i]].g, pal.data[n.lookup[i]].b);
73 fontRenderClass *fontRenderClass::getInstance()
78 FT_Error myFTC_Face_Requester(FTC_FaceID face_id,
80 FT_Pointer request_data,
83 return ((fontRenderClass*)request_data)->FTC_Face_Requester(face_id, aface);
87 FT_Error fontRenderClass::FTC_Face_Requester(FTC_FaceID face_id, FT_Face* aface)
89 fontListEntry *font=(fontListEntry *)face_id;
93 // eDebug("[FONT] FTC_Face_Requester (%s)", font->face.c_str());
96 if ((error=FT_New_Face(library, font->filename.c_str(), 0, aface)))
98 eDebug(" failed: %s", strerror(error));
101 FT_Select_Charmap(*aface, ft_encoding_unicode);
105 FTC_FaceID fontRenderClass::getFaceID(const std::string &face)
107 for (fontListEntry *f=font; f; f=f->next)
110 return (FTC_FaceID)f;
115 FT_Error fontRenderClass::getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit)
117 FT_Error res=FTC_SBit_Cache_Lookup(sbitsCache, font, glyph_index, sbit);
121 FT_Error fontRenderClass::getGlyphImage(FTC_Image_Desc *font, FT_ULong glyph_index, FT_Glyph *glyph, FT_Glyph *borderglyph, int bordersize)
124 FT_Error err = FTC_ImageCache_Lookup(imageCache, font, glyph_index, &image, NULL);
129 err = FT_Glyph_Copy(image, glyph);
133 if (borderglyph && bordersize)
135 err = FT_Glyph_Copy(image, borderglyph);
137 if (bordersize != strokerRadius)
139 strokerRadius = bordersize;
140 FT_Stroker_Set(stroker, strokerRadius, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
142 err = FT_Glyph_Stroke(borderglyph, stroker, 1);
147 std::string fontRenderClass::AddFont(const std::string &filename, const std::string &name, int scale)
149 eDebugNoNewLine("[FONT] adding font %s...", filename.c_str());
152 fontListEntry *n=new fontListEntry;
156 singleLock s(ftlock);
158 if ((error=FT_New_Face(library, filename.c_str(), 0, &face)))
159 eFatal(" failed: %s", strerror(error));
161 n->filename=filename;
166 eDebug("OK (%s)", n->face.c_str());
172 fontRenderClass::fontListEntry::~fontListEntry()
176 fontRenderClass::fontRenderClass(): fb(fbClass::getInstance())
179 eDebug("[FONT] initializing lib...");
181 if (FT_Init_FreeType(&library))
183 eDebug("[FONT] initializing failed.");
187 eDebug("[FONT] loading fonts...");
191 int maxbytes=4*1024*1024;
192 eDebug("[FONT] Intializing font cache, using max. %dMB...", maxbytes/1024/1024);
195 if (FTC_Manager_New(library, 8, 8, maxbytes, myFTC_Face_Requester, this, &cacheManager))
197 eDebug("[FONT] initializing font cache failed!");
202 eDebug("[FONT] initializing font cache manager error.");
205 if (FTC_SBit_Cache_New(cacheManager, &sbitsCache))
207 eDebug("[FONT] initializing font cache sbit failed!");
210 if (FTC_Image_Cache_New(cacheManager, &imageCache))
212 eDebug("[FONT] initializing font cache imagecache failed!");
214 if (FT_Stroker_New(library, &stroker))
216 eDebug("[FONT] initializing font stroker failed!");
223 float fontRenderClass::getLineHeight(const gFont& font)
228 getFont(fnt, font.family.c_str(), font.pointSize);
231 singleLock s(ftlock);
232 FT_Face current_face;
233 if ((FTC_Manager_LookupFace(cacheManager, fnt->scaler.face_id, ¤t_face) < 0) ||
234 (FTC_Manager_LookupSize(cacheManager, &fnt->scaler, &fnt->size) < 0))
236 eDebug("FTC_Manager_Lookup_Size failed!");
239 int linegap=current_face->size->metrics.height-(current_face->size->metrics.ascender+current_face->size->metrics.descender);
240 float height=(current_face->size->metrics.ascender+current_face->size->metrics.descender+linegap)/64.0;
244 fontRenderClass::~fontRenderClass()
246 singleLock s(ftlock);
249 fontListEntry *f=font;
253 // auskommentiert weil freetype und enigma die kritische masse des suckens ueberschreiten.
254 // FTC_Manager_Done(cacheManager);
255 // FT_Done_FreeType(library);
258 int fontRenderClass::getFont(ePtr<Font> &font, const std::string &face, int size, int tabwidth)
260 FTC_FaceID id=getFaceID(face);
266 font = new Font(this, id, size * ((fontListEntry*)id)->scale / 100, tabwidth);
270 void addFont(const char *filename, const char *alias, int scale_factor, int is_replacement)
272 fontRenderClass::getInstance()->AddFont(filename, alias, scale_factor);
274 eTextPara::setReplacementFont(alias);
279 Font::Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tw): tabwidth(tw)
282 font.face_id = faceid;
285 font.flags = FT_LOAD_DEFAULT;
286 scaler.face_id = faceid;
287 scaler.width = isize;
288 scaler.height = isize;
293 // font.image_type |= ftc_image_flag_autohinted;
296 FT_Error Font::getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit)
298 return renderer->getGlyphBitmap(&font, glyph_index, sbit);
301 FT_Error Font::getGlyphImage(FT_ULong glyph_index, FT_Glyph *glyph, FT_Glyph *borderglyph, int bordersize)
303 return renderer->getGlyphImage(&font, glyph_index, glyph, borderglyph, bordersize);
310 DEFINE_REF(eTextPara);
312 int eTextPara::appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags, int border, bool activate_newcolor, unsigned long newcolor)
314 int xadvance, left, top, height;
320 /* TODO: scale border radius with current_font scaling */
321 if (current_font->getGlyphImage(glyphIndex, &ng.image, &ng.borderimage, 64 * border))
323 if (ng.image && ng.image->format != FT_GLYPH_FORMAT_BITMAP)
325 FT_Glyph_To_Bitmap(&ng.image, FT_RENDER_MODE_NORMAL, NULL, 1);
326 if (ng.image->format != FT_GLYPH_FORMAT_BITMAP) return 1;
328 if (ng.borderimage && ng.borderimage->format != FT_GLYPH_FORMAT_BITMAP)
330 FT_Glyph_To_Bitmap(&ng.borderimage, FT_RENDER_MODE_NORMAL, NULL, 1);
331 if (ng.borderimage->format != FT_GLYPH_FORMAT_BITMAP) return 1;
333 FT_BitmapGlyph glyph = NULL;
336 xadvance = ng.borderimage->advance.x;
339 /* Move the first character, to make sure the border does not get cut off by the boundingbox (xborder is in pixel units, so just divide the width difference by two) */
340 xborder = (((FT_BitmapGlyph)ng.borderimage)->bitmap.width - ((FT_BitmapGlyph)ng.image)->bitmap.width) / 2;
342 glyph = (FT_BitmapGlyph)ng.borderimage;
346 xadvance = ng.image->advance.x;
347 glyph = (FT_BitmapGlyph)ng.image;
357 height = glyph->bitmap.rows;
362 if (current_font->getGlyphBitmap(glyphIndex, &glyph))
365 xadvance = glyph->xadvance;
368 height = glyph->height;
381 glyphString::reverse_iterator i(glyphs.rbegin());
382 /* find first possibility (from end to begin) to break */
383 while (i != glyphs.rend())
385 if (i->flags&(GS_CANBREAK|GS_ISFIRST)) /* stop on either space/hyphen/shy or start of line (giving up) */
392 if (i != glyphs.rend() /* ... we found anything */
393 && (i->flags&GS_CANBREAK) /* ...and this is a space/hyphen/soft-hyphen */
394 && (!(i->flags & GS_ISFIRST)) /* ...and this is not an start of line (line with just a single space/hyphen) */
395 && cnt ) /* ... and there are actual non-space characters after this */
397 /* if we have a soft-hyphen, and used that for breaking, turn it into a real hyphen */
398 if (i->flags & GS_SOFTHYPHEN)
400 i->flags &= ~GS_SOFTHYPHEN;
401 i->flags |= GS_HYPHEN;
403 --i; /* skip the space/hypen/softhyphen */
404 int linelength=cursor.x()-i->x;
405 i->flags|=GS_ISFIRST; /* make this a line start */
406 ePoint offset=ePoint(i->x, i->y);
410 /* and move everything to the end into the next line. */
415 i->bbox.moveBy(-offset.x(), -offset.y());
418 } while (i-- != glyphs.rbegin()); // rearrange them into the next line
419 cursor+=ePoint(linelength, 0); // put the cursor after that line
431 if (previous && use_kerning)
434 FT_Get_Kerning(current_face, previous, glyphIndex, ft_kerning_default, &delta);
438 ng.bbox.setLeft( ((flags&GS_ISFIRST)|(cursor.x()-1))+left );
439 ng.bbox.setTop( cursor.y() - top );
440 ng.bbox.setHeight( height );
442 xadvance += kern + xborder;
443 ng.bbox.setWidth(xadvance);
445 ng.x = cursor.x()+kern+xborder;
448 ng.font = current_font;
449 ng.glyph_index = glyphIndex;
452 if (activate_newcolor)
454 ng.flags |= GS_COLORCHANGE;
455 ng.newcolor = newcolor;
458 glyphs.push_back(ng);
461 /* when we have a SHY, don't xadvance. It will either be the last in the line (when used for breaking), or not displayed. */
462 if (!(flags & GS_SOFTHYPHEN))
463 cursor += ePoint(xadvance, 0);
464 previous = glyphIndex;
468 void eTextPara::calc_bbox()
479 glyphString::iterator i(glyphs.begin());
484 for (; i != glyphs.end(); ++i)
486 if (i->flags & (GS_ISSPACE|GS_SOFTHYPHEN))
488 if ( i->bbox.left() < boundBox.left() )
489 boundBox.setLeft( i->bbox.left() );
490 if ( i->bbox.top() < boundBox.top() )
491 boundBox.setTop( i->bbox.top() );
492 if ( i->bbox.right() > boundBox.right() )
493 boundBox.setRight( i->bbox.right() );
494 if ( i->bbox.bottom() > boundBox.bottom() )
495 boundBox.setBottom( i->bbox.bottom() );
497 // eDebug("boundBox left = %i, top = %i, right = %i, bottom = %i", boundBox.left(), boundBox.top(), boundBox.right(), boundBox.bottom() );
500 void eTextPara::newLine(int flags)
502 if (maximum.width()<cursor.x())
503 maximum.setWidth(cursor.x());
506 int linegap=current_face->size->metrics.height-(current_face->size->metrics.ascender+current_face->size->metrics.descender);
508 lineOffsets.push_back(cursor.y());
509 lineChars.push_back(charCount);
512 cursor+=ePoint(0, (current_face->size->metrics.ascender+current_face->size->metrics.descender+linegap)>>6);
514 if (maximum.height()<cursor.y())
515 maximum.setHeight(cursor.y());
519 eTextPara::~eTextPara()
524 void eTextPara::setFont(const gFont *font)
526 ePtr<Font> fnt, replacement;
527 fontRenderClass::getInstance()->getFont(fnt, font->family.c_str(), font->pointSize);
529 eWarning("FONT '%s' MISSING!", font->family.c_str());
530 fontRenderClass::getInstance()->getFont(replacement, replacement_facename.c_str(), font->pointSize);
531 setFont(fnt, replacement);
534 std::string eTextPara::replacement_facename;
535 std::set<int> eTextPara::forced_replaces;
537 void eTextPara::setFont(Font *fnt, Font *replacement)
542 replacement_font=replacement;
543 singleLock s(ftlock);
545 // we ask for replacment_font first becauseof the cache
546 if (replacement_font)
548 if ((FTC_Manager_LookupFace(fontRenderClass::instance->cacheManager,
549 replacement_font->scaler.face_id,
550 &replacement_face) < 0) ||
551 (FTC_Manager_LookupSize(fontRenderClass::instance->cacheManager,
552 &replacement_font->scaler,
553 &replacement_font->size) < 0))
555 eDebug("FTC_Manager_Lookup_Size failed!");
561 if ((FTC_Manager_LookupFace(fontRenderClass::instance->cacheManager,
562 current_font->scaler.face_id,
563 ¤t_face) < 0) ||
564 (FTC_Manager_LookupSize(fontRenderClass::instance->cacheManager,
565 ¤t_font->scaler,
566 ¤t_font->size) < 0))
568 eDebug("FTC_Manager_Lookup_Size failed!");
573 use_kerning=FT_HAS_KERNING(current_face);
577 shape (std::vector<unsigned long> &string, const std::vector<unsigned long> &text);
579 int eTextPara::renderString(const char *string, int rflags, int border)
581 singleLock s(ftlock);
586 if ((FTC_Manager_LookupFace(fontRenderClass::instance->cacheManager,
587 current_font->scaler.face_id,
588 ¤t_face) < 0) ||
589 (FTC_Manager_LookupSize(fontRenderClass::instance->cacheManager,
590 ¤t_font->scaler,
591 ¤t_font->size) < 0))
593 eDebug("FTC_Manager_Lookup_Size failed!");
598 eFatal("eTextPara::renderString: no current_face");
599 if (!current_face->size)
600 eFatal("eTextPara::renderString: no current_face->size");
604 cursor=ePoint(area.x(), area.y()+(current_face->size->metrics.ascender>>6));
608 std::vector<unsigned long> uc_string, uc_visual;
610 uc_string.reserve(strlen(string));
612 const char *p = string ? string : "";
616 unsigned int unicode=(unsigned char)*p++;
618 if (unicode & 0x80) // we have (hopefully) UTF8 here, and we assume that the encoding is VALID
620 if ((unicode & 0xE0)==0xC0) // two bytes
625 unicode|=(*p++)&0x3F;
626 } else if ((unicode & 0xF0)==0xE0) // three bytes
631 unicode|=(*p++)&0x3F;
634 unicode|=(*p++)&0x3F;
635 } else if ((unicode & 0xF8)==0xF0) // four bytes
640 unicode|=(*p++)&0x3F;
643 unicode|=(*p++)&0x3F;
646 unicode|=(*p++)&0x3F;
649 uc_string.push_back(unicode);
652 std::vector<unsigned long> uc_shape;
654 // character -> glyph conversion
655 shape(uc_shape, uc_string);
657 // now do the usual logical->visual reordering
658 int size=uc_shape.size();
659 FriBidiCharType dir=FRIBIDI_TYPE_ON;
660 uc_visual.resize(size);
661 // gaaanz lahm, aber anders geht das leider nicht, sorry.
662 FriBidiChar array[size], target[size];
663 std::copy(uc_shape.begin(), uc_shape.end(), array);
664 fribidi_log2vis(array, size, &dir, target, 0, 0, 0);
665 uc_visual.assign(target, target+size);
667 glyphs.reserve(size);
669 unsigned long newcolor = 0;
670 bool activate_newcolor = false;
673 for (std::vector<unsigned long>::const_iterator i(uc_visual.begin());
674 i != uc_visual.end(); ++i)
677 int flags = nextflags;
679 unsigned long chr = *i;
681 if (!(rflags&RS_DIRECT))
687 unsigned long c = *(i+1);
703 for (codeidx = 0; codeidx < 8; codeidx++)
705 if ((i + 2 + codeidx) == uc_visual.end()) break;
706 color[codeidx] = (char)((*(i + 2 + codeidx)) & 0xff);
710 newcolor = gRGB(color).argb();
711 activate_newcolor = true;
724 cursor+=ePoint(current_font->tabwidth, 0);
725 cursor-=ePoint(cursor.x()%current_font->tabwidth, 0);
730 newline:isprintable=0;
732 nextflags|=GS_ISFIRST;
735 case 0x86: case 0xE086:
736 case 0x87: case 0xE087:
737 nprint: isprintable=0;
739 case 0xAD: // soft-hyphen
740 flags |= GS_SOFTHYPHEN;
741 chr = 0x2010; /* hyphen */
757 /* FIXME: our font doesn't seem to have a hyphen, so use hyphen-minus for it. */
761 if (forced_replaces.find(chr) == forced_replaces.end())
762 index=(rflags&RS_DIRECT)? chr : FT_Get_Char_Index(current_face, chr);
766 if (replacement_face)
767 index=(rflags&RS_DIRECT)? chr : FT_Get_Char_Index(replacement_face, chr);
770 eDebug("unicode U+%4lx not present", chr);
772 appendGlyph(replacement_font, replacement_face, index, flags, rflags, border, activate_newcolor, newcolor);
774 appendGlyph(current_font, current_face, index, flags, rflags, border, activate_newcolor, newcolor);
776 activate_newcolor = false;
781 if (dir & FRIBIDI_MASK_RTL)
784 doTopBottomReordering=true;
789 lineOffsets.push_back(cursor.y());
790 lineChars.push_back(charCount);
797 void eTextPara::blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground, bool border)
799 if (glyphs.empty()) return;
801 singleLock s(ftlock);
806 if ((FTC_Manager_LookupFace(fontRenderClass::instance->cacheManager,
807 current_font->scaler.face_id,
808 ¤t_face) < 0) ||
809 (FTC_Manager_LookupSize(fontRenderClass::instance->cacheManager,
810 ¤t_font->scaler,
811 ¤t_font->size) < 0))
813 eDebug("FTC_Manager_Lookup_Size failed!");
817 ePtr<gPixmap> target;
818 dc.getPixmap(target);
819 gSurface *surface = target->surface;
820 gRGB currentforeground = foreground;
822 register int opcode = -1;
824 gColor *lookup8, lookup8_invert[16];
825 gColor *lookup8_normal=0;
827 __u16 lookup16_normal[16], lookup16_invert[16], *lookup16;
828 __u32 lookup32_normal[16], lookup32_invert[16], *lookup32;
830 gRegion area(eRect(0, 0, surface->x, surface->y));
831 gRegion clip = dc.getClip() & area;
833 int buffer_stride=surface->stride;
835 bool setcolor = true;
836 std::list<int>::reverse_iterator line_offs_it(lineOffsets.rbegin());
837 std::list<int>::iterator line_chars_it(lineChars.begin());
840 for (glyphString::iterator i(glyphs.begin()); i != glyphs.end(); ++i, --line_chars)
844 line_offs = *(line_offs_it++);
845 line_chars = *(line_chars_it++);
847 if (i->flags & GS_COLORCHANGE)
849 /* don't do colorchanges in borders */
852 currentforeground = i->newcolor;
859 if (surface->bpp == 8)
861 if (surface->clut.data)
863 lookup8_normal=getColor(surface->clut, background, currentforeground).lookup;
867 lookup8_invert[i] = lookup8_normal[i^0xF];
872 } else if (surface->bpp == 16)
875 for (int i = 0; i != 16; ++i)
877 #define BLEND(y, x, a) (y + (((x-y) * a)>>8))
878 unsigned char da = background.a, dr = background.r, dg = background.g, db = background.b;
882 dr = BLEND(background.r, foreground.r, sa) & 0xFF;
883 dg = BLEND(background.g, foreground.g, sa) & 0xFF;
884 db = BLEND(background.b, foreground.b, sa) & 0xFF;
887 #if BYTE_ORDER == LITTLE_ENDIAN
888 lookup16_normal[i] = bswap_16(((db >> 3) << 11) | ((dg >> 2) << 5) | (dr >> 3));
890 lookup16_normal[i] = ((db >> 3) << 11) | ((dg >> 2) << 5) | (dr >> 3);
894 for (int i=0; i<16; ++i)
895 lookup16_invert[i]=lookup16_normal[i^0xF];
896 } else if (surface->bpp == 32)
899 for (int i=0; i<16; ++i)
901 #define BLEND(y, x, a) (y + (((x-y) * a)>>8))
903 unsigned char da = background.a, dr = background.r, dg = background.g, db = background.b;
907 da = BLEND(background.a, currentforeground.a, sa) & 0xFF;
908 dr = BLEND(background.r, currentforeground.r, sa) & 0xFF;
909 dg = BLEND(background.g, currentforeground.g, sa) & 0xFF;
910 db = BLEND(background.b, currentforeground.b, sa) & 0xFF;
914 lookup32_normal[i]=db | (dg << 8) | (dr << 16) | (da << 24);;
916 for (int i=0; i<16; ++i)
917 lookup32_invert[i]=lookup32_normal[i^0xF];
920 eWarning("can't render to %dbpp", surface->bpp);
924 if (i->flags & GS_SOFTHYPHEN)
927 if (!(i->flags & GS_INVERT))
929 lookup8 = lookup8_normal;
930 lookup16 = lookup16_normal;
931 lookup32 = lookup32_normal;
934 lookup8 = lookup8_invert;
935 lookup16 = lookup16_invert;
936 lookup32 = lookup32_invert;
947 FT_BitmapGlyph glyph = border ? (FT_BitmapGlyph)i->borderimage : (FT_BitmapGlyph)i->image;
948 if (!glyph->bitmap.buffer) continue;
949 rxbase = i->x + glyph->left + offset.x();
950 rybase = (doTopBottomReordering ? line_offs : i->y) - glyph->top + offset.y();
951 sbase = glyph->bitmap.buffer;
952 sxbase = glyph->bitmap.width;
953 sybase = glyph->bitmap.rows;
954 pitch = glyph->bitmap.pitch;
958 static FTC_SBit glyph_bitmap;
959 if (fontRenderClass::instance->getGlyphBitmap(&i->font->font, i->glyph_index, &glyph_bitmap))
961 rxbase=i->x+glyph_bitmap->left + offset.x();
962 rybase=(doTopBottomReordering ? line_offs : i->y) - glyph_bitmap->top + offset.y();
963 sbase=glyph_bitmap->buffer;
964 sxbase=glyph_bitmap->width;
965 sybase=glyph_bitmap->height;
966 pitch = glyph_bitmap->pitch;
968 dbase = (__u8*)(surface->data)+buffer_stride*rybase+rxbase*surface->bypp;
969 for (unsigned int c = 0; c < clip.rects.size(); ++c)
971 int rx = rxbase, ry = rybase;
974 register int sx = sxbase;
976 if ((sy+ry) >= clip.rects[c].bottom())
977 sy=clip.rects[c].bottom()-ry;
978 if ((sx+rx) >= clip.rects[c].right())
979 sx=clip.rects[c].right()-rx;
980 if (rx < clip.rects[c].left())
982 int diff=clip.rects[c].left()-rx;
986 d+=diff*surface->bypp;
988 if (ry < clip.rects[c].top())
990 int diff=clip.rects[c].top()-ry;
994 d+=diff*buffer_stride;
996 if ((sx>0) && (sy>0))
998 int extra_source_stride = pitch - sx;
1001 case 0: // 4bit lookup to 8bit
1003 register int extra_buffer_stride = buffer_stride - sx;
1004 register __u8 *td=d;
1005 for (int ay = 0; ay < sy; ay++)
1008 for (ax=0; ax<sx; ax++)
1010 register int b=(*s++)>>4;
1015 s += extra_source_stride;
1016 td += extra_buffer_stride;
1020 case 1: // 8bit direct
1022 register int extra_buffer_stride = buffer_stride - sx;
1023 register __u8 *td=d;
1024 for (int ay = 0; ay < sy; ay++)
1027 for (ax=0; ax<sx; ax++)
1029 register int b=*s++;
1032 s += extra_source_stride;
1033 td += extra_buffer_stride;
1039 int extra_buffer_stride = (buffer_stride >> 1) - sx;
1040 register __u16 *td = (__u16*)d;
1041 for (int ay = 0; ay != sy; ay++)
1044 for (ax = 0; ax != sx; ax++)
1046 register int b = (*s++) >> 4;
1051 s += extra_source_stride;
1052 td += extra_buffer_stride;
1058 register int extra_buffer_stride = (buffer_stride >> 2) - sx;
1059 register __u32 *td=(__u32*)d;
1060 for (int ay = 0; ay < sy; ay++)
1063 for (ax=0; ax<sx; ax++)
1065 register int b=(*s++)>>4;
1070 s += extra_source_stride;
1071 td += extra_buffer_stride;
1083 void eTextPara::realign(int dir) // der code hier ist ein wenig merkwuerdig.
1085 glyphString::iterator begin(glyphs.begin()), c(glyphs.begin()), end(glyphs.begin()), last;
1088 while (c != glyphs.end())
1091 int numspaces=0, num=0;
1094 ASSERT( end != glyphs.end());
1096 // zeilenende suchen
1100 } while ((end != glyphs.end()) && (!(end->flags&GS_ISFIRST)));
1101 // end zeigt jetzt auf begin der naechsten zeile
1103 for (c=begin; c!=end; ++c)
1105 // space am zeilenende skippen
1106 if ((c==last) && (c->flags&GS_ISSPACE))
1109 if (c->flags&GS_ISSPACE)
1120 int offset=area.width()-linelength;
1123 offset+=area.left();
1124 while (begin != end)
1126 begin->bbox.moveBy(offset-begin->x,0);
1135 if (end == glyphs.end()) // letzte zeile linksbuendig lassen
1142 if ((!spacemode) && (num<2))
1144 int off=(area.width()-linelength)*256/(spacemode?numspaces:(num-1));
1146 while (begin != end)
1149 if ((!spacemode) || (begin->flags&GS_ISSPACE))
1151 begin->x+=curoff>>8;
1152 begin->bbox.moveBy(curoff>>8,0);
1165 void eTextPara::clear()
1167 singleLock s(ftlock);
1170 replacement_font = 0;
1172 for (unsigned int i = 0; i < glyphs.size(); i++)
1174 if (glyphs[i].image) FT_Done_Glyph(glyphs[i].image);
1175 if (glyphs[i].borderimage) FT_Done_Glyph(glyphs[i].borderimage);
1180 eAutoInitP0<fontRenderClass> init_fontRenderClass(eAutoInitNumbers::graphic-1, "Font Render Class");