X11 platform: Add optional use of the pango library to draw text, gaining the possibility to draw text in any script supported by Unicode.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12153 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-12-21 15:05:02 +00:00
parent 00ebcd23aa
commit 461750c38e
11 changed files with 759 additions and 324 deletions

View File

@ -17,13 +17,17 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
New Features and Extensions
- (add here)
- Added '--enable-print' option to configure effective under X11 platforms
and with 'yes' default value. Using '--enable-print=no' removes print
and PostScript support from the FLTK library, thus reducing its size.
- Added Fl_Surface_Device::push_current(new_surface) and
Fl_Surface_Device::pop_current() to set/unset the current surface
receiving graphics commands.
- X11 platform: Added support for drawing text with the pango library
which allows to draw most scripts supported by Unicode, including CJK
and right-to-left scripts. The corresponding CMake option is
OPTION_USE_PANGO. The corresponding configure option is --enable-pango.
This option is OFF by default.
New Configuration Options (ABI Version)

View File

@ -372,8 +372,46 @@ endif(OPTION_USE_XCURSOR)
#######################################################################
if(X11_Xft_FOUND)
option(OPTION_USE_XFT "use lib Xft" ON)
option(OPTION_USE_PANGO "use lib Pango" OFF)
endif(X11_Xft_FOUND)
#######################################################################
if(X11_Xft_FOUND AND OPTION_USE_PANGO)
#this covers Debian, Ubuntu, FreeBSD, NetBSD, Darwin
if(APPLE AND OPTION_APPLE_X11)
list(APPEND CMAKE_INCLUDE_PATH /sw/include)
list(APPEND CMAKE_LIBRARY_PATH /sw/lib)
endif(APPLE AND OPTION_APPLE_X11)
find_file(HAVE_PANGO_H pango-1.0/pango/pango.h ${CMAKE_INCLUDE_PATH})
find_file(HAVE_PANGOXFT_H pango-1.0/pango/pangoxft.h ${CMAKE_INCLUDE_PATH})
if(HAVE_PANGO_H AND HAVE_PANGOXFT_H)
find_library(HAVE_LIB_PANGO pango-1.0 ${CMAKE_LIBRARY_PATH})
find_library(HAVE_LIB_PANGOXFT pangoxft-1.0 ${CMAKE_LIBRARY_PATH})
if(APPLE)
set(HAVE_LIB_GOBJECT TRUE)
else()
find_library(HAVE_LIB_GOBJECT gobject-2.0 ${CMAKE_LIBRARY_PATH})
endif(APPLE)
endif(HAVE_PANGO_H AND HAVE_PANGOXFT_H)
if(HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT)
set(USE_PANGO TRUE)
message(STATUS "USE_PANGO=" ${USE_PANGO})
#remove last 3 components of HAVE_PANGO_H and put in PANGO_H_PREFIX
get_filename_component(PANGO_H_PREFIX ${HAVE_PANGO_H} PATH)
get_filename_component(PANGO_H_PREFIX ${PANGO_H_PREFIX} PATH)
get_filename_component(PANGO_H_PREFIX ${PANGO_H_PREFIX} PATH)
get_filename_component(PANGOLIB_DIR ${HAVE_LIB_PANGO} PATH)
#glib.h is usually in ${PANGO_H_PREFIX}/glib-2.0/ ...
find_path(GLIB_H_PATH glib.h ${PANGO_H_PREFIX}/glib-2.0)
if(NOT GLIB_H_PATH) # ... but not under NetBSD
find_path(GLIB_H_PATH glib.h ${PANGO_H_PREFIX}/glib/glib-2.0)
endif(NOT GLIB_H_PATH)
include_directories(${PANGO_H_PREFIX}/pango-1.0 ${GLIB_H_PATH} ${PANGOLIB_DIR}/glib-2.0/include)
endif(HAVE_LIB_PANGO AND HAVE_LIB_PANGOXFT AND HAVE_LIB_GOBJECT)
endif(X11_Xft_FOUND AND OPTION_USE_PANGO)
if(OPTION_USE_XFT)
set(USE_XFT X11_Xft_FOUND)
list(APPEND FLTK_LDLIBS -lXft)

View File

@ -91,6 +91,14 @@
#cmakedefine01 USE_XFT
/*
* USE_PANGO:
*
* Use the pango library to draw UTF8 text.
*/
#cmakedefine USE_PANGO 1
/*
* HAVE_XDBE:
*

View File

@ -85,11 +85,19 @@
/*
* USE_XFT
*
* Use the new Xft library to draw anti-aliased text.
* Use the Xft library to draw anti-aliased text.
*/
#define USE_XFT 0
/*
* USE_PANGO
*
* Use the pango library to draw UTF-8 text.
*/
#define USE_PANGO 0
/*
* HAVE_XDBE:
*

View File

@ -1041,6 +1041,41 @@ case $host_os_gui in
fi
fi
dnl Check for the pango library unless disabled...
AC_ARG_ENABLE(pango, [ --enable-pango turn on Pango support [[default=no]]])
pango_found=no
if test x$enable_pango = xyes; then
case $host_os in
darwin*)
CXXFLAGS="-I/sw/include/pango-1.0 -I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include $CXXFLAGS"
PANGOLIBDIR="-L/sw/lib"
;;
linux*)
CXXFLAGS="-I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include $CXXFLAGS"
CXXFLAGS="-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/glib-2.0/include $CXXFLAGS"
;;
freebsd*)
CXXFLAGS="-I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include $CXXFLAGS"
;;
netbsd*)
CXXFLAGS="-I/usr/pkg/include/pango-1.0 -I/usr/pkg/include/glib-2.0 -I/usr/pkg/lib/glib-2.0/include $CXXFLAGS"
CXXFLAGS="-I/usr/pkg/include/glib/glib-2.0 $CXXFLAGS"
PANGOLIBDIR="-L/usr/pkg/lib"
LDFLAGS="-Wl,-rpath,/usr/pkg/lib $LDFLAGS"
;;
esac
CPPFLAGS="$PANGOLIBDIR $CXXFLAGS"
AC_CHECK_HEADER(pango/pango.h,
AC_CHECK_HEADER(pango/pangoxft.h,
AC_CHECK_LIB(pango-1.0, pango_layout_new,
AC_CHECK_LIB(pangoxft-1.0, pango_xft_render_layout,
AC_DEFINE(USE_PANGO)
pango_found=yes
LIBS="$PANGOLIBDIR -lpango-1.0 -lpangoxft-1.0 -lgobject-2.0 $LIBS"))))
CPPFLAGS=$CXXFLAGS
fi
dnl Check for the Xdbe extension unless disabled...
AC_ARG_ENABLE(xdbe, [ --enable-xdbe turn on Xdbe support [[default=yes]]])
@ -1507,6 +1542,9 @@ case $host_os_gui in
if test x$xrender_found = xyes; then
graphics="$graphics + Xrender"
fi
if test x$pango_found = xyes; then
graphics="$graphics + pango"
fi
;;
esac

View File

@ -620,8 +620,9 @@ void fl_draw(const char *, int x, int y) <br>
void fl_draw(const char *, int n, int x, int y)
\par
Draw a nul-terminated string or an array of \p n characters
starting at the given location. Text is aligned to the left and to
Draw a nul-terminated string or an array of \p n bytes
starting at the given location. In both cases, the text must be UTF-8 encoded.
Text is aligned to the left and to
the baseline of the font. To align to the bottom, subtract
\p %fl_descent() from \p y.
To align to the top, subtract \p %fl_descent() and add \p %fl_height().
@ -629,6 +630,11 @@ This version of \p %fl_draw() provides direct access to
the text drawing function of the underlying OS. It does not apply any
special handling to control characters.
void fl_rtl_draw(const char *str, int n, int x, int y)
\par
Draw a UTF-8 string of length n bytes right to left starting at the given x, y location.
void fl_draw(const char* str, int x, int y, int w, int h, Fl_Align align, Fl_Image* img, int draw_symbols)
\par
@ -775,6 +781,17 @@ FLTK expects individual characters, characters that are not part of
a string, in UCS-4 encoding, which is also ASCII compatible, but
requires 4 bytes to store a Unicode character.
FLTK can draw accurately any Unicode-supported script for which the system
contains relevant fonts. Under X11 platforms, this requires
to build the library with the OPTION_USE_PANGO CMake option turned On
(or with configure --enable-pango).
Plain text drawing starting at a user-given coordinate
is well supported by FLTK, including for right-to-left scripts.
Further text-related operations
(i.e., selection, formatting, input, and editing) are functional with
left-to-right scripts only.
For more information about character encodings, see the chapter on
\ref unicode.

View File

@ -470,6 +470,13 @@ if (HAVE_XRENDER)
list (APPEND OPTIONAL_LIBS ${X11_Xrender_LIB})
endif (HAVE_XRENDER)
if (USE_PANGO)
list (APPEND OPTIONAL_LIBS ${HAVE_LIB_PANGO} ${HAVE_LIB_PANGOXFT})
if(NOT APPLE)
list (APPEND OPTIONAL_LIBS ${HAVE_LIB_GOBJECT} )
endif(NOT APPLE)
endif(USE_PANGO)
if (USE_XFT)
list (APPEND OPTIONAL_LIBS ${X11_Xft_LIB})
if (LIB_fontconfig)

View File

@ -45,8 +45,12 @@ public:
Fl_Fontsize size; /**< font size */
#ifndef FL_DOXYGEN // don't bother with platorm dependant details in the doc.
# if USE_XFT
XftFont* font;
//const char* encoding;
# if USE_PANGO
int descent_;
int height_;
# else
XftFont* font;
# endif
int angle;
FL_EXPORT Fl_Font_Descriptor(const char* xfontname, Fl_Fontsize size, int angle);
# else

View File

@ -1,8 +1,7 @@
//
// "$Id$"
//
// Definition of classes Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
// for the Fast Light Tool Kit (FLTK).
// Definition of class Fl_Xlib_Graphics_Driver for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2016 by Bill Spitzak and others.
//
@ -43,12 +42,31 @@ struct _XRegion {
};
#endif // HAVE_X11_XREGION_H
#if USE_PANGO
#include <pango/pangoxft.h>
#endif
/**
\brief The Xlib-specific graphics class.
*
This class is implemented only on the Xlib platform.
*/
class FL_EXPORT Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver {
#if USE_XFT
void drawUCS4(const void *str, int n, int x, int y);
#endif
#if USE_PANGO
friend class Fl_X11_Screen_Driver;
static PangoContext *pctxt_;
static PangoFontMap *pfmap_;
static PangoLayout *playout_;
protected:
PangoFontDescription *pfd_;
void do_draw(int from_right, const char *str, int n, int x, int y);
static PangoContext *context();
static void init_built_in_fonts();
#endif
protected:
static GC gc_;
uchar **mask_bitmap_;
@ -59,9 +77,13 @@ protected:
XPOINT *p;
int line_width_;
int clip_x(int x);
#if USE_XFT
static Window draw_window;
static struct _XftDraw* draw_;
#endif
public:
Fl_Xlib_Graphics_Driver(void);
virtual ~Fl_Xlib_Graphics_Driver() { if (p) free(p); }
virtual ~Fl_Xlib_Graphics_Driver();
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
virtual void *gc() { return gc_; }
virtual void gc(void *value);
@ -100,7 +122,7 @@ public:
Fl_Region XRectangleRegion(int x, int y, int w, int h);
void XDestroyRegion(Fl_Region r);
protected:
void transformed_vertex0(short x, short y);
virtual void transformed_vertex0(short x, short y);
void fixloop();
// --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/xlib_rect.cxx
void point(int x, int y);

View File

@ -57,8 +57,20 @@ Fl_Xlib_Graphics_Driver::Fl_Xlib_Graphics_Driver(void) {
p_size = 0;
p = NULL;
line_width_ = 0;
#if USE_PANGO
pfd_ = pango_font_description_new();
Fl_Graphics_Driver::font(0, 0);
#endif
}
Fl_Xlib_Graphics_Driver::~Fl_Xlib_Graphics_Driver() {
if (p) free(p);
#if USE_PANGO
pango_font_description_free(pfd_);
#endif
}
void Fl_Xlib_Graphics_Driver::gc(void *value) {
gc_ = (GC)value;
fl_gc = gc_;

File diff suppressed because it is too large Load Diff