diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index cb2b87905..de3dfdcd6 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -217,9 +217,11 @@ class ImageDraw(object): return text.split(split_character) - def text(self, xy, text, fill=None, font=None, anchor=None, *args, **kwargs): + def text(self, xy, text, fill=None, font=None, anchor=None, + *args, **kwargs): if self._multiline_check(text): - return self.multiline_text(xy, text, fill, font, anchor, *args, **kwargs) + return self.multiline_text(xy, text, fill, font, anchor, + *args, **kwargs) ink, fill = self._getink(fill) if font is None: font = self.getfont() diff --git a/PIL/features.py b/PIL/features.py index 8a70080ca..134d85abf 100644 --- a/PIL/features.py +++ b/PIL/features.py @@ -5,7 +5,6 @@ modules = { "tkinter": "PIL._imagingtk", "freetype2": "PIL._imagingft", "littlecms2": "PIL._imagingcms", - "raqm": "PIL._imagingft", "webp": "PIL._webp", "transp_webp": ("WEBP", "WebPDecoderBuggyAlpha") } diff --git a/Tests/test_imagefontctl.py b/Tests/test_imagefontctl.py index 2a6463159..32999b169 100644 --- a/Tests/test_imagefontctl.py +++ b/Tests/test_imagefontctl.py @@ -1,22 +1,23 @@ # -*- coding: utf-8 -*- from helper import unittest, PillowTestCase from PIL import Image -from PIL import ImageDraw +from PIL import ImageDraw, ImageFont + +#check if raqm installed +have_raqm = ImageFont.core.have_raqm FONT_SIZE = 20 FONT_PATH = "Tests/fonts/DejaVuSans.ttf" try: from PIL import ImageFont - - # check if raqm is available + ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) im = Image.new(mode='RGB', size=(300, 100)) draw = ImageDraw.Draw(im) draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr') - + @unittest.skipIf(not have_raqm, "Raqm Library is not installed !") class TestImagecomplextext(PillowTestCase): - def test_complex_text(self): ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) diff --git a/_imagingft.c b/_imagingft.c index d1bbe5822..2725f3022 100644 --- a/_imagingft.c +++ b/_imagingft.c @@ -43,14 +43,6 @@ #define FT_ERROR_END_LIST { 0, 0 } }; #ifdef HAVE_RAQM #include -#else -typedef enum -{ - RAQM_DIRECTION_DEFAULT, - RAQM_DIRECTION_RTL, - RAQM_DIRECTION_LTR, - RAQM_DIRECTION_TTB -} raqm_direction_t; #endif typedef struct @@ -830,6 +822,14 @@ setup_module(PyObject* m) { #endif PyDict_SetItemString(d, "freetype2_version", v); + +#ifdef HAVE_RAQM + v = PyBool_FromLong(1); +#else + v = PyBool_FromLong(0); +#endif + PyDict_SetItemString(d, "have_raqm", v); + return 0; } diff --git a/docs/installation.rst b/docs/installation.rst index 9de91ea7d..263cb4e70 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -171,6 +171,9 @@ Many of Pillow's features require external libraries: so it is unlikely to work with any Python prior to 3.5 on Windows. * **libraqm** provides complex text layout support. + * libraqm provides bidirectional text support (using FriBiDi), shaping (using HarfBuzz), and proper script itemization. As a result, Raqm can support most writing systems covered by Unicode. + * libraqm depends on the following libraries: FreeType, HarfBuzz, FriBiDi, make sure that install them before install libraqm if not available as package in your system. + * setting text direction or font features is not supported without libraqm. Once you have installed the prerequisites, run:: @@ -203,14 +206,16 @@ Build Options * Build flags: ``--disable-zlib``, ``--disable-jpeg``, ``--disable-tiff``, ``--disable-freetype``, ``--disable-tcl``, ``--disable-tk``, ``--disable-lcms``, ``--disable-webp``, - ``--disable-webpmux``, ``--disable-jpeg2000``, ``--disable-imagequant``. + ``--disable-webpmux``, ``--disable-jpeg2000``, + ``--disable-imagequant``, ``--disable-raqm``. Disable building the corresponding feature even if the development libraries are present on the building machine. * Build flags: ``--enable-zlib``, ``--enable-jpeg``, ``--enable-tiff``, ``--enable-freetype``, ``--enable-tcl``, ``--enable-tk``, ``--enable-lcms``, ``--enable-webp``, - ``--enable-webpmux``, ``--enable-jpeg2000``, ``--enable-imagequant``. + ``--enable-webpmux``, ``--enable-jpeg2000``, + ``--enable-imagequant``, ``--enable-raqm``. Require that the corresponding feature is built. The build will raise an exception if the libraries are not found. Webpmux (WebP metadata) relies on WebP support. Tcl and Tk also must be used together. @@ -248,7 +253,16 @@ The easiest way to install external libraries is via `Homebrew $ brew install libtiff libjpeg webp little-cms2 -Install Pillow with:: +To install libraqm on MaxOS use Homebrew:: + $ brew install freetype harfbuzz fribidi +Once you have `libraqm source code `_ and the dependencies , run the customary sequence of commands in the source code +directory:: + + $ ./configure + $ make + $ make install + +Now install Pillow with:: $ pip install Pillow @@ -278,7 +292,7 @@ Or for Python 3:: Prerequisites are installed on **FreeBSD 10** with:: - $ sudo pkg install jpeg tiff webp lcms2 freetype2 + $ sudo pkg install jpeg tiff webp lcms2 freetype2 harfbuzz fribidi Building on Linux diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index 20d76cce0..2a83b9268 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -240,12 +240,13 @@ Methods the number of pixels between lines. :param align: If the text is passed on to multiline_text(), "left", "center" or "right". - :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. + :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. Requires libraqm :param features: A list of font feature to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example 'dlig' or 'ss01', but can be also used to turn off default font features for example '-liga' to disable ligatures or '-kern' to disable kerning. To get all supported features, see https://www.microsoft.com/typography/otspec/featurelist.htm + Requires libraqm. .. py:method:: PIL.ImageDraw.Draw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=0, align="left", direction=None, features=[]) @@ -258,12 +259,13 @@ Methods :param font: An :py:class:`~PIL.ImageFont.ImageFont` instance. :param spacing: The number of pixels between lines. :param align: "left", "center" or "right". - :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. + :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. Requires libraqm. :param features: A list of font feature to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example 'dlig' or 'ss01', but can be also used to turn off default font features for example '-liga' to disable ligatures or '-kern' to disable kerning. To get all supported features, see https://www.microsoft.com/typography/otspec/featurelist.htm + Requires libraqm. .. py:method:: PIL.ImageDraw.Draw.textsize(text, font=None, spacing=0) diff --git a/docs/reference/ImageFont.rst b/docs/reference/ImageFont.rst index 3a0b06732..46df1e4f7 100644 --- a/docs/reference/ImageFont.rst +++ b/docs/reference/ImageFont.rst @@ -63,12 +63,13 @@ Methods driver prefers; if empty, the renderer may return either mode. Note that the mode is always a string, to simplify C-level implementations. - :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. + :param direction: Direction of the text. It can be 'rtl', 'ltr', 'ttb' or 'btt'. Requires libraqm :param features: A list of font feature to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example 'dlig' or 'ss01', but can be also used to turn off default font features for example '-liga' to disable ligatures or '-kern' to disable kerning. To get all supported features, see https://www.microsoft.com/typography/otspec/featurelist.htm + Requires libraqm .. versionadded:: 1.1.5 :return: An internal PIL storage memory instance as defined by the