From e07a254ed9cdd82ab5c1fc727592cb4bde1ba35f Mon Sep 17 00:00:00 2001 From: Fahad Al-Saidi Date: Thu, 15 Dec 2016 14:43:02 +0400 Subject: [PATCH] update --- PIL/ImageDraw.py | 6 ++++-- PIL/features.py | 1 - Tests/test_imagefontctl.py | 11 ++++++----- _imagingft.c | 16 ++++++++-------- docs/installation.rst | 29 +++++++++++++++++++++++++---- docs/reference/ImageDraw.rst | 6 ++++-- docs/reference/ImageFont.rst | 3 ++- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index 9d003d587..d0e95df65 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -202,9 +202,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 11b1fe058..e01a32193 100644 --- a/PIL/features.py +++ b/PIL/features.py @@ -5,7 +5,6 @@ modules = { "tkinter": "PIL._tkinter_finder", "freetype2": "PIL._imagingft", "littlecms2": "PIL._imagingcms", - "raqm": "PIL._imagingft", "webp": "PIL._webp", } 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 277239a8f..1bbb327b3 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -170,6 +170,16 @@ Many of Pillow's features require external libraries: * Windows support: Libimagequant requires VS2013/MSVC 18 to compile, 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:: $ pip install Pillow @@ -201,14 +211,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. @@ -247,7 +259,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 @@ -277,7 +298,7 @@ Or for Python 3:: Prerequisites are installed on **FreeBSD 10 or 11** with:: - $ sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg + $ sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg harfbuzz fribidi Building on Linux diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index cd1236563..e8f67f39b 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 c01872a6b..d8790ca01 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