Changeset View
Changeset View
Standalone View
Standalone View
kcms/kfontinst/lib/FcEngine.cpp
Show First 20 Lines • Show All 383 Lines • ▼ Show 20 Line(s) | |||||
384 | } | 384 | } | ||
385 | 385 | | |||
386 | bool CFcEngine::Xft::drawString(XftFont *xftFont, const QString &text, int x, int &y, int h) const | 386 | bool CFcEngine::Xft::drawString(XftFont *xftFont, const QString &text, int x, int &y, int h) const | ||
387 | { | 387 | { | ||
388 | XGlyphInfo extents; | 388 | XGlyphInfo extents; | ||
389 | const FcChar16 *str=(FcChar16 *)(text.utf16()); | 389 | const FcChar16 *str=(FcChar16 *)(text.utf16()); | ||
390 | 390 | | |||
391 | XftTextExtents16(QX11Info::display(), xftFont, str, text.length(), &extents); | 391 | XftTextExtents16(QX11Info::display(), xftFont, str, text.length(), &extents); | ||
392 | if(y+extents.height<h) | 392 | if(y+extents.height<=h) | ||
393 | XftDrawString16(itsDraw, &itsTxtColor, xftFont, x, y+extents.y, str, text.length()); | 393 | XftDrawString16(itsDraw, &itsTxtColor, xftFont, x, y+extents.y, str, text.length()); | ||
394 | if(extents.height>0) | 394 | if(extents.height>0) | ||
395 | { | 395 | { | ||
396 | y+=extents.height; | 396 | y+=extents.height; | ||
397 | return true; | 397 | return true; | ||
398 | } | 398 | } | ||
399 | return false; | 399 | return false; | ||
400 | } | 400 | } | ||
▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Line(s) | 695 | { | |||
754 | } | 754 | } | ||
755 | } | 755 | } | ||
756 | } | 756 | } | ||
757 | } | 757 | } | ||
758 | 758 | | |||
759 | return img; | 759 | return img; | ||
760 | } | 760 | } | ||
761 | 761 | | |||
762 | QImage CFcEngine::draw(const QString &name, quint32 style, int faceNo, const QColor &txt, const QColor &bgnd, int fSize, const QString &text_) | ||||
763 | { | ||||
764 | QImage img; | ||||
765 | QString text = text_; | ||||
766 | | ||||
767 | if(!name.isEmpty() && | ||||
768 | ((name==itsName && style==itsStyle) || | ||||
769 | parse(name, style, faceNo)) ) | ||||
770 | { | ||||
771 | | ||||
772 | getSizes(); | ||||
773 | | ||||
774 | if(itsSizes.size()) | ||||
775 | { | ||||
776 | if(!itsScalable) // Then need to get nearest size... | ||||
777 | { | ||||
778 | int bSize=0; | ||||
779 | | ||||
780 | for(int s=0; s<itsSizes.size(); ++s) | ||||
781 | if (itsSizes[s]<=fSize || 0==bSize) | ||||
782 | bSize=itsSizes[s]; | ||||
783 | fSize=bSize; | ||||
784 | } | ||||
785 | | ||||
786 | int h = fSize; | ||||
787 | int w = 0; | ||||
788 | | ||||
789 | XftFont *xftFont=getFont(fSize); | ||||
790 | | ||||
791 | if(xftFont) | ||||
792 | { | ||||
793 | XGlyphInfo extents; | ||||
794 | const FcChar16 *str=(FcChar16 *)(text.utf16()); | ||||
795 | | ||||
796 | XftTextExtents16(QX11Info::display(), xftFont, str, text.length(), | ||||
797 | &extents); | ||||
798 | | ||||
799 | h = extents.height; | ||||
800 | w = extents.width; | ||||
801 | | ||||
802 | bool needAlpha(bgnd.alpha()<255); | ||||
803 | | ||||
804 | if(xft()->init(needAlpha ? Qt::black : txt, needAlpha ? Qt::white : bgnd, w, h)) | ||||
805 | { | ||||
806 | bool rv=false; | ||||
807 | | ||||
808 | if(hasStr(xftFont, text) || hasStr(xftFont, text=text.toUpper()) || | ||||
809 | hasStr(xftFont, text=text.toLower())) | ||||
810 | { | ||||
811 | XGlyphInfo extents; | ||||
812 | const FcChar16 *str=(FcChar16 *)(text.utf16()); | ||||
813 | | ||||
814 | XftTextExtents16(QX11Info::display(), xftFont, str, text.length(), | ||||
815 | &extents); | ||||
816 | | ||||
817 | int x=0, | ||||
818 | y=0; | ||||
819 | | ||||
820 | rv=xft()->drawString(xftFont, text, x, y, h); | ||||
821 | } | ||||
822 | else | ||||
823 | { | ||||
824 | int x=0, | ||||
825 | y=0; | ||||
826 | QRect used; | ||||
827 | | ||||
828 | rv=xft()->drawAllGlyphs(xftFont, h, x, y, w, h, true, text.length(), &used); | ||||
829 | } | ||||
830 | | ||||
831 | if(rv) | ||||
832 | { | ||||
833 | img=xft()->toImage(w, h); | ||||
834 | if(!img.isNull()) | ||||
835 | { | ||||
836 | img=img.copy(0, 0, w, h); | ||||
837 | | ||||
838 | if(needAlpha) | ||||
839 | setTransparentBackground(img, txt); | ||||
840 | } | ||||
841 | } | ||||
842 | } | ||||
843 | closeFont(xftFont); | ||||
844 | } | ||||
845 | } | ||||
846 | } | ||||
847 | | ||||
848 | return img; | ||||
849 | } | ||||
850 | | ||||
762 | QImage CFcEngine::draw(const QString &name, quint32 style, int faceNo, const QColor &txt, const QColor &bgnd, | 851 | QImage CFcEngine::draw(const QString &name, quint32 style, int faceNo, const QColor &txt, const QColor &bgnd, | ||
763 | int w, int h, bool thumb, const QList<TRange> &range, QList<TChar> *chars) | 852 | int w, int h, bool thumb, const QList<TRange> &range, QList<TChar> *chars) | ||
764 | { | 853 | { | ||
765 | QImage img; | 854 | QImage img; | ||
766 | const qreal dpr = qApp->devicePixelRatio(); | 855 | const qreal dpr = qApp->devicePixelRatio(); | ||
767 | w = w * dpr; | 856 | w = w * dpr; | ||
768 | h = h * dpr; | 857 | h = h * dpr; | ||
769 | bool rv=false; | 858 | bool rv=false; | ||
▲ Show 20 Lines • Show All 706 Lines • Show Last 20 Lines |