Lines 123-128
Link Here
|
123 |
|
123 |
|
124 |
#include <hash_set> |
124 |
#include <hash_set> |
125 |
|
125 |
|
|
|
126 |
struct cairo_surface_t; |
127 |
struct cairo_t; |
128 |
struct cairo_font_face_t; |
129 |
typedef void* FT_Face; |
130 |
struct cairo_matrix_t { |
131 |
double xx; double yx; |
132 |
double xy; double yy; |
133 |
double x0; double y0; |
134 |
}; |
135 |
struct cairo_glyph_t |
136 |
{ |
137 |
unsigned long index; |
138 |
double x; |
139 |
double y; |
140 |
}; |
141 |
|
126 |
using namespace rtl; |
142 |
using namespace rtl; |
127 |
|
143 |
|
128 |
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
144 |
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
Lines 734-739
Link Here
|
734 |
} |
750 |
} |
735 |
|
751 |
|
736 |
//-------------------------------------------------------------------------- |
752 |
//-------------------------------------------------------------------------- |
|
|
753 |
namespace { |
754 |
|
755 |
class CairoWrapper |
756 |
{ |
757 |
private: |
758 |
bool mbIsValid; |
759 |
|
760 |
cairo_surface_t* (*mp_xlib_surface_create)(Display *, Drawable , Visual *, int , int ); |
761 |
void (*mp_surface_destroy)(cairo_surface_t *); |
762 |
cairo_t* (*mp_create)(cairo_surface_t *); |
763 |
void (*mp_destroy)(cairo_t*); |
764 |
void (*mp_clip)(cairo_t*); |
765 |
void (*mp_rectangle)(cairo_t*, double, double, double, double); |
766 |
cairo_font_face_t * (*mp_ft_font_face_create_for_ft_face)(FT_Face, int); |
767 |
void (*mp_set_font_face)(cairo_t *, cairo_font_face_t *); |
768 |
void (*mp_font_face_destroy)(cairo_font_face_t *); |
769 |
void (*mp_matrix_init_scale)(cairo_matrix_t *, double, double); |
770 |
void (*mp_matrix_rotate)(cairo_matrix_t *, double); |
771 |
void (*mp_set_font_matrix)(cairo_t *, const cairo_matrix_t *); |
772 |
void (*mp_show_glyphs)(cairo_t *, const cairo_glyph_t *, int ); |
773 |
void (*mp_set_source_rgb)(cairo_t *, double , double , double ); |
774 |
|
775 |
oslGenericFunction loadSymbol( const char* ); |
776 |
CairoWrapper(); |
777 |
public: |
778 |
static CairoWrapper& get(); |
779 |
bool isValid() const { return mbIsValid; } |
780 |
|
781 |
cairo_surface_t* xlib_surface_create(Display *pDisplay, Drawable drawable, Visual *pVisual, int width, int height) |
782 |
{ return (*mp_xlib_surface_create)(pDisplay, drawable, pVisual, width, height); } |
783 |
void surface_destroy(cairo_surface_t *surface) { (*mp_surface_destroy)(surface); } |
784 |
cairo_t* create(cairo_surface_t *surface) { return (*mp_create)(surface); } |
785 |
void destroy(cairo_t *cr) { (*mp_destroy)(cr); } |
786 |
void clip(cairo_t *cr) { (*mp_clip)(cr); } |
787 |
void rectangle(cairo_t *cr, double x, double y, double width, double height) |
788 |
{ (*mp_rectangle)(cr, x, y, width, height); } |
789 |
cairo_font_face_t* ft_font_face_create_for_ft_face(FT_Face face, int load_flags) |
790 |
{ return (*mp_ft_font_face_create_for_ft_face)(face, load_flags); } |
791 |
void set_font_face(cairo_t *cr, cairo_font_face_t *font_face) |
792 |
{ (*mp_set_font_face)(cr, font_face); } |
793 |
void font_face_destroy(cairo_font_face_t *font_face) |
794 |
{ (*mp_font_face_destroy)(font_face); } |
795 |
void matrix_init_scale(cairo_matrix_t *matrix, double sx, double sy) |
796 |
{ (*mp_matrix_init_scale)(matrix, sx, sy); } |
797 |
void matrix_rotate(cairo_matrix_t *matrix, double radians) |
798 |
{ (*mp_matrix_rotate)(matrix, radians); } |
799 |
void set_font_matrix(cairo_t *cr, const cairo_matrix_t *matrix) |
800 |
{ (*mp_set_font_matrix)(cr, matrix); } |
801 |
void show_glyphs(cairo_t *cr, const cairo_glyph_t *glyphs, int no_glyphs) |
802 |
{ (*mp_show_glyphs)(cr, glyphs, no_glyphs); } |
803 |
void set_source_rgb(cairo_t *cr, double red, double green, double blue) |
804 |
{ (*mp_set_source_rgb)(cr, red, green, blue); } |
805 |
}; |
806 |
|
807 |
static CairoWrapper* pOneInstance = NULL; |
808 |
|
809 |
CairoWrapper& CairoWrapper::get() |
810 |
{ |
811 |
if( ! pOneInstance ) |
812 |
pOneInstance = new CairoWrapper(); |
813 |
return *pOneInstance; |
814 |
} |
815 |
|
816 |
oslGenericFunction CairoWrapper::loadSymbol( const char* pSymbol ) |
817 |
{ |
818 |
OUString aSym( OUString::createFromAscii( pSymbol ) ); |
819 |
oslGenericFunction pSym = osl_getFunctionSymbol( NULL, aSym.pData ); |
820 |
#if OSL_DEBUG_LEVEL > 1 |
821 |
fprintf( stderr, "%s %s\n", pSymbol, pSym ? "found" : "not found" ); |
822 |
#endif |
823 |
return pSym; |
824 |
} |
825 |
|
826 |
CairoWrapper::CairoWrapper() : mbIsValid(false) |
827 |
{ |
828 |
static const char* pDisableCairoText = getenv( "SAL_DISABLE_CAIROTEXT" ); |
829 |
if( pDisableCairoText && (pDisableCairoText[0] == '1') ) |
830 |
return; |
831 |
|
832 |
mp_xlib_surface_create = (cairo_surface_t* (*)(Display *, Drawable , Visual *, int , int )) |
833 |
loadSymbol( "cairo_xlib_surface_create" ); |
834 |
mp_surface_destroy = (void(*)(cairo_surface_t*)) |
835 |
loadSymbol( "cairo_surface_destroy" ); |
836 |
mp_create = (cairo_t*(*)(cairo_surface_t*)) |
837 |
loadSymbol( "cairo_create" ); |
838 |
mp_destroy = (void(*)(cairo_t*)) |
839 |
loadSymbol( "cairo_destroy" ); |
840 |
mp_clip = (void(*)(cairo_t*)) |
841 |
loadSymbol( "cairo_clip" ); |
842 |
mp_rectangle = (void(*)(cairo_t*, double, double, double, double)) |
843 |
loadSymbol( "cairo_rectangle" ); |
844 |
mp_ft_font_face_create_for_ft_face = (cairo_font_face_t * (*)(FT_Face, int)) |
845 |
loadSymbol( "cairo_ft_font_face_create_for_ft_face" ); |
846 |
mp_set_font_face = (void (*)(cairo_t *, cairo_font_face_t *)) |
847 |
loadSymbol( "cairo_set_font_face" ); |
848 |
mp_font_face_destroy = (void (*)(cairo_font_face_t *)) |
849 |
loadSymbol( "cairo_font_face_destroy" ); |
850 |
mp_matrix_init_scale = (void (*)(cairo_matrix_t *, double, double)) |
851 |
loadSymbol( "cairo_matrix_init_scale" ); |
852 |
mp_matrix_rotate = (void (*)(cairo_matrix_t *, double)) |
853 |
loadSymbol( "cairo_matrix_rotate" ); |
854 |
mp_set_font_matrix = (void (*)(cairo_t *, const cairo_matrix_t *)) |
855 |
loadSymbol( "cairo_set_font_matrix" ); |
856 |
mp_show_glyphs = (void (*)(cairo_t *, const cairo_glyph_t *, int )) |
857 |
loadSymbol( "cairo_show_glyphs" ); |
858 |
mp_set_source_rgb = (void (*)(cairo_t *, double , double , double )) |
859 |
loadSymbol( "cairo_set_source_rgb" ); |
860 |
|
861 |
mbIsValid = |
862 |
( |
863 |
mp_xlib_surface_create && |
864 |
mp_surface_destroy && |
865 |
mp_create && |
866 |
mp_destroy && |
867 |
mp_clip && |
868 |
mp_rectangle && |
869 |
mp_ft_font_face_create_for_ft_face && |
870 |
mp_set_font_face && |
871 |
mp_font_face_destroy && |
872 |
mp_matrix_init_scale && |
873 |
mp_matrix_rotate && |
874 |
mp_set_font_matrix && |
875 |
mp_show_glyphs && |
876 |
mp_set_source_rgb |
877 |
); |
878 |
if (!mbIsValid) |
879 |
{ |
880 |
#if OSL_DEBUG_LEVEL > 1 |
881 |
fprintf( stderr, "not all needed symbols were found in libfontconfig\n" ); |
882 |
#endif |
883 |
} |
884 |
} |
885 |
|
886 |
} //namespace |
887 |
|
888 |
void X11SalGraphics::DrawCairoAAFontString( const ServerFontLayout& rLayout ) |
889 |
{ |
890 |
Display* pDisplay = GetXDisplay(); |
891 |
Visual* pVisual = GetDisplay()->GetVisual( GetScreenNumber() ).GetVisual(); |
892 |
CairoWrapper &rCairo = CairoWrapper::get(); |
893 |
|
894 |
cairo_surface_t *surface = rCairo.xlib_surface_create (pDisplay, |
895 |
hDrawable_, pVisual, 1, 1); |
896 |
|
897 |
cairo_t *cr = rCairo.create (surface); |
898 |
rCairo.surface_destroy (surface); |
899 |
|
900 |
if( pClipRegion_ && !XEmptyRegion( pClipRegion_ ) ) |
901 |
{ |
902 |
XRectangle aXRect; |
903 |
XClipBox( pClipRegion_, &aXRect ); |
904 |
rCairo.rectangle(cr, aXRect.x, aXRect.y, aXRect.width, aXRect.height); |
905 |
rCairo.clip(cr); |
906 |
} |
907 |
|
908 |
rCairo.set_source_rgb(cr, |
909 |
SALCOLOR_RED(nTextColor_)/255.0, |
910 |
SALCOLOR_GREEN(nTextColor_)/255.0, |
911 |
SALCOLOR_BLUE(nTextColor_)/255.0); |
912 |
|
913 |
ServerFont& rFont = rLayout.GetServerFont(); |
914 |
|
915 |
cairo_font_face_t* font_face = |
916 |
rCairo.ft_font_face_create_for_ft_face(rFont.GetFtFace(), rFont.GetLoadFlags()); |
917 |
|
918 |
rCairo.set_font_face(cr, font_face); |
919 |
|
920 |
cairo_matrix_t m; |
921 |
const ImplFontSelectData& rFSD = rFont.GetFontSelData(); |
922 |
int nWidth = rFSD.mnWidth ? rFSD.mnWidth : rFSD.mnHeight; |
923 |
rCairo.matrix_init_scale(&m, nWidth, rFSD.mnHeight); |
924 |
if (rLayout.GetOrientation()) |
925 |
rCairo.matrix_rotate(&m, (3600 - rLayout.GetOrientation()) * M_PI / 1800.0); |
926 |
rCairo.set_font_matrix(cr, &m); |
927 |
|
928 |
std::vector<cairo_glyph_t> cairo_glyphs; |
929 |
sal_Int32 nGlyph; |
930 |
Point aPos; |
931 |
int nStart = 0; |
932 |
while (rLayout.GetNextGlyphs( 1, &nGlyph, aPos, nStart )) |
933 |
{ |
934 |
cairo_glyph_t aGlyph; |
935 |
aGlyph.index = nGlyph; |
936 |
aGlyph.x = aPos.X(); |
937 |
aGlyph.y = aPos.Y(); |
938 |
cairo_glyphs.push_back(aGlyph); |
939 |
} |
940 |
|
941 |
if (!cairo_glyphs.empty()) |
942 |
rCairo.show_glyphs (cr, &cairo_glyphs[0], cairo_glyphs.size()); |
943 |
|
944 |
rCairo.font_face_destroy(font_face); |
945 |
|
946 |
rCairo.destroy (cr); |
947 |
} |
948 |
|
949 |
//-------------------------------------------------------------------------- |
737 |
|
950 |
|
738 |
void X11SalGraphics::DrawServerAAFontString( const ServerFontLayout& rLayout ) |
951 |
void X11SalGraphics::DrawServerAAFontString( const ServerFontLayout& rLayout ) |
739 |
{ |
952 |
{ |
Lines 1111-1125
Link Here
|
1111 |
// draw complex text |
1324 |
// draw complex text |
1112 |
ServerFont& rFont = rLayout.GetServerFont(); |
1325 |
ServerFont& rFont = rLayout.GetServerFont(); |
1113 |
|
1326 |
|
1114 |
X11GlyphPeer& rGlyphPeer = X11GlyphCache::GetInstance().GetPeer(); |
1327 |
if (rFont.GetFtFace() && CairoWrapper::get().isValid()) |
1115 |
if( rGlyphPeer.GetGlyphSet( rFont, m_nScreen ) ) |
1328 |
DrawCairoAAFontString( rLayout ); |
1116 |
DrawServerAAFontString( rLayout ); |
1329 |
else |
|
|
1330 |
{ |
1331 |
X11GlyphPeer& rGlyphPeer = X11GlyphCache::GetInstance().GetPeer(); |
1332 |
if( rGlyphPeer.GetGlyphSet( rFont, m_nScreen ) ) |
1333 |
DrawServerAAFontString( rLayout ); |
1117 |
#ifndef MACOSX /* ignore X11 fonts on MACOSX */ |
1334 |
#ifndef MACOSX /* ignore X11 fonts on MACOSX */ |
1118 |
else if( !rGlyphPeer.ForcedAntialiasing( rFont, m_nScreen ) ) |
1335 |
else if( !rGlyphPeer.ForcedAntialiasing( rFont, m_nScreen ) ) |
1119 |
DrawServerSimpleFontString( rLayout ); |
1336 |
DrawServerSimpleFontString( rLayout ); |
1120 |
#endif // MACOSX |
1337 |
#endif // MACOSX |
1121 |
else |
1338 |
else |
1122 |
DrawServerAAForcedString( rLayout ); |
1339 |
DrawServerAAForcedString( rLayout ); |
|
|
1340 |
} |
1123 |
} |
1341 |
} |
1124 |
|
1342 |
|
1125 |
//-------------------------------------------------------------------------- |
1343 |
//-------------------------------------------------------------------------- |