Add replacement functions for gdk ones.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2011 22:06:03 +0000 (22:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2011 22:06:03 +0000 (22:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66323

Patch by Rafael Antognolli <antognolli@profusion.mobi> on 2011-09-09
Reviewed by Martin Robinson.

.:

* Source/cmake/FindPango.cmake:

Source/WebCore:

This will allow the EFL port to don't depend on gdk anymore.

No new functionality so no new tests.

* CMakeListsEfl.txt:
* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::appendRegionToCairoContext):
* platform/graphics/cairo/CairoUtilities.h:
* platform/graphics/pango/FontPango.cpp:
(WebCore::drawGlyphsShadow):
(WebCore::Font::drawComplexText):
* platform/graphics/pango/PangoUtilities.cpp: Added.
(WebCore::getLineClipRegionFromLayoutIter):
(WebCore::getClipRegionFromPangoLayoutLine):
* platform/graphics/pango/PangoUtilities.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94876 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/WebCore/CMakeListsEfl.txt
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
Source/WebCore/platform/graphics/cairo/CairoUtilities.h
Source/WebCore/platform/graphics/pango/FontPango.cpp
Source/WebCore/platform/graphics/pango/PangoUtilities.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/pango/PangoUtilities.h [new file with mode: 0644]
Source/cmake/FindPango.cmake

index 7b9e9dd..9475f53 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-09-09  Rafael Antognolli  <antognolli@profusion.mobi>
+
+        Add replacement functions for gdk ones.
+        https://bugs.webkit.org/show_bug.cgi?id=66323
+
+        Reviewed by Martin Robinson.
+
+        * Source/cmake/FindPango.cmake:
+
 2011-09-09  Laszlo Gombos  <laszlo.1.gombos@nokia.com>
 
         [Qt] Remove common.pri
index feeea6d..3fb5708 100644 (file)
@@ -128,9 +128,11 @@ IF (WTF_USE_CAIRO)
       platform/graphics/pango/FontPlatformDataPango.cpp
       platform/graphics/pango/GlyphPageTreeNodePango.cpp
       platform/graphics/pango/SimpleFontDataPango.cpp
+      platform/graphics/pango/PangoUtilities.cpp
     )
     LIST(APPEND WebCore_LIBRARIES
-      ${Pango_LIBRARIES}
+      ${Pango_LIBRARY}
+      ${Pango_Cairo_LIBRARY}
     )
   ENDIF ()
 ENDIF ()
index bb6e191..7fbd163 100644 (file)
@@ -1,3 +1,26 @@
+2011-09-09  Rafael Antognolli  <antognolli@profusion.mobi>
+
+        Add replacement functions for gdk ones.
+        https://bugs.webkit.org/show_bug.cgi?id=66323
+
+        Reviewed by Martin Robinson.
+
+        This will allow the EFL port to don't depend on gdk anymore.
+
+        No new functionality so no new tests.
+
+        * CMakeListsEfl.txt:
+        * platform/graphics/cairo/CairoUtilities.cpp:
+        (WebCore::appendRegionToCairoContext):
+        * platform/graphics/cairo/CairoUtilities.h:
+        * platform/graphics/pango/FontPango.cpp:
+        (WebCore::drawGlyphsShadow):
+        (WebCore::Font::drawComplexText):
+        * platform/graphics/pango/PangoUtilities.cpp: Added.
+        (WebCore::getLineClipRegionFromLayoutIter):
+        (WebCore::getClipRegionFromPangoLayoutLine):
+        * platform/graphics/pango/PangoUtilities.h: Added.
+
 2011-09-09  Mark Hahnenberg  <mhahnenberg@apple.com>
 
         Unzip initialization lists and constructors in JSCell hierarchy (5/7)
index b4adb6c..1632259 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Igalia S.L.
+ * Copyright (C) 2011 ProFUSION embedded systems
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -80,6 +81,19 @@ void appendWebCorePathToCairoContext(cairo_t* context, const Path& path)
     appendPathToCairoContext(context, path.platformPath()->context());
 }
 
+void appendRegionToCairoContext(cairo_t* to, const cairo_region_t* region)
+{
+    if (!region)
+        return;
+
+    const int rectCount = cairo_region_num_rectangles(region);
+    for (int i = 0; i < rectCount; ++i) {
+        cairo_rectangle_int_t rect;
+        cairo_region_get_rectangle(region, i, &rect);
+        cairo_rectangle(to, rect.x, rect.y, rect.width, rect.height);
+    }
+}
+
 cairo_operator_t toCairoOperator(CompositeOperator op)
 {
     switch (op) {
index 2110050..3d6eb79 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Igalia S.L.
+ * Copyright (C) 2011 ProFUSION embedded systems
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -43,6 +44,7 @@ void setSourceRGBAFromColor(cairo_t*, const Color&);
 void appendPathToCairoContext(cairo_t* to, cairo_t* from);
 void setPathOnCairoContext(cairo_t* to, cairo_t* from);
 void appendWebCorePathToCairoContext(cairo_t* context, const Path& path);
+void appendRegionToCairoContext(cairo_t*, const cairo_region_t*);
 cairo_operator_t toCairoOperator(CompositeOperator op);
 void drawPatternToCairoContext(cairo_t* cr, cairo_surface_t* image, const IntSize& imageSize, const FloatRect& tileRect,
                                const AffineTransform& patternTransform, const FloatPoint& phase, cairo_operator_t op, const FloatRect& destRect);
index 5001598..2684f53 100644 (file)
@@ -6,6 +6,7 @@
  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
  * Copyright (C) 2008 Xan Lopez <xan@gnome.org>
  * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2011 ProFUSION embedded systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "SimpleFontData.h"
 #include "TextRun.h"
 #include <cairo.h>
-#include <gdk/gdk.h>
 #include <pango/pango.h>
 #include <pango/pangocairo.h>
 
+#if PLATFORM(GTK)
+#include <gdk/gdk.h>
+#else
+#include "PangoUtilities.h"
+#endif
+
 #if USE(FREETYPE)
 #include <pango/pangofc-fontmap.h>
 #endif
@@ -234,7 +240,11 @@ static void drawGlyphsShadow(GraphicsContext* graphicsContext, const FloatPoint&
         cairo_translate(context, totalOffset.x(), totalOffset.y());
 
         setSourceRGBAFromColor(context, graphicsContext->state().shadowColor);
+#if PLATFORM(GTK)
         gdk_cairo_region(context, renderRegion);
+#else
+        appendRegionToCairoContext(context, renderRegion);
+#endif
         cairo_clip(context);
         pango_cairo_show_layout_line(context, layoutLine);
 
@@ -256,7 +266,11 @@ static void drawGlyphsShadow(GraphicsContext* graphicsContext, const FloatPoint&
         cairo_t* context = graphicsContext->platformContext()->cr();
         cairo_save(context);
         cairo_translate(context, totalOffset.x(), totalOffset.y());
+#if PLATFORM(GTK)
         gdk_cairo_region(context, renderRegion);
+#else
+        appendRegionToCairoContext(context, renderRegion);
+#endif
         cairo_clip(context);
         cairo_translate(context, -totalOffset.x(), -totalOffset.y());
 
@@ -291,7 +305,11 @@ void Font::drawComplexText(GraphicsContext* context, const TextRun& run, const F
     char* start = g_utf8_offset_to_pointer(utf8, from);
     char* end = g_utf8_offset_to_pointer(start, to - from);
     int ranges[] = {start - utf8, end - utf8};
+#if PLATFORM(GTK)
     partialRegion = gdk_pango_layout_line_get_clip_region(layoutLine, 0, 0, ranges, 1);
+#else
+    partialRegion = getClipRegionFromPangoLayoutLine(layoutLine, ranges);
+#endif
 
     drawGlyphsShadow(context, point, layoutLine, partialRegion);
 
@@ -301,7 +319,11 @@ void Font::drawComplexText(GraphicsContext* context, const TextRun& run, const F
     float red, green, blue, alpha;
     context->fillColor().getRGBA(red, green, blue, alpha);
     cairo_set_source_rgba(cr, red, green, blue, alpha);
-    gdk_cairo_region(cr, partialRegion);
+#if PLATFORM(GTK)
+        gdk_cairo_region(cr, partialRegion);
+#else
+        appendRegionToCairoContext(cr, partialRegion);
+#endif
     cairo_clip(cr);
 
     pango_cairo_show_layout_line(cr, layoutLine);
diff --git a/Source/WebCore/platform/graphics/pango/PangoUtilities.cpp b/Source/WebCore/platform/graphics/pango/PangoUtilities.cpp
new file mode 100644 (file)
index 0000000..98dc11b
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * This code was mostly copied from gdk-pango.
+ * source: http://git.gnome.org/browse/gtk+/tree/gdk/gdkpango.c
+ *
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 2011 ProFUSION embedded systems
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "PangoUtilities.h"
+
+#include <cairo.h>
+#include <pango/pango.h>
+
+namespace WebCore {
+
+static cairo_region_t* getLineClipRegionFromLayoutIter(PangoLayoutIter* iter, const int* indexRange)
+{
+    PangoRectangle logicalRect;
+    PangoLayoutLine* line = pango_layout_iter_get_line_readonly(iter);
+    cairo_region_t* clipRegion = cairo_region_create();
+    pango_layout_iter_get_line_extents(iter, 0, &logicalRect);
+    int baseline = pango_layout_iter_get_baseline(iter);
+
+    int* pixelRanges = 0;
+    int pixelRangeCount = 0;
+
+    if (indexRange[1] >= line->start_index
+        && indexRange[0] < line->start_index + line->length)
+        pango_layout_line_get_x_ranges(line,
+                                       indexRange[0],
+                                       indexRange[1],
+                                       &pixelRanges, &pixelRangeCount);
+
+    for (int j = 0; j < pixelRangeCount; ++j) {
+        int offsetX = PANGO_PIXELS(pixelRanges[2 * j] - logicalRect.x);
+        int offsetY = PANGO_PIXELS(baseline - logicalRect.y);
+
+        cairo_rectangle_int_t rect;
+        rect.x = offsetX;
+        rect.y = -offsetY;
+        rect.width = PANGO_PIXELS(pixelRanges[2 * j + 1] - logicalRect.x) - offsetX;
+        rect.height = PANGO_PIXELS(baseline - logicalRect.y + logicalRect.height) - offsetY;
+
+        cairo_region_union_rectangle(clipRegion, &rect);
+    }
+
+    free(pixelRanges);
+
+    return clipRegion;
+}
+
+cairo_region_t* getClipRegionFromPangoLayoutLine(PangoLayoutLine* line, const int* indexRange)
+{
+    if (!indexRange)
+        return 0;
+
+    PangoLayoutIter* iter = pango_layout_get_iter(line->layout);
+    while (pango_layout_iter_get_line_readonly(iter) != line)
+        pango_layout_iter_next_line(iter);
+
+    cairo_region_t* clipRegion = getLineClipRegionFromLayoutIter(iter, indexRange);
+
+    pango_layout_iter_free(iter);
+
+    return clipRegion;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/pango/PangoUtilities.h b/Source/WebCore/platform/graphics/pango/PangoUtilities.h
new file mode 100644 (file)
index 0000000..b800676
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 2011 ProFUSION embedded systems
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PangoUtilities_h
+#define PangoUtilities_h
+
+#include "GraphicsTypes.h"
+
+typedef struct _PangoLayoutLine PangoLayoutLine;
+typedef struct _cairo_region cairo_region_t;
+
+namespace WebCore {
+
+cairo_region_t* getClipRegionFromPangoLayoutLine(PangoLayoutLine*, const int* indexRange);
+
+} // namespace WebCore
+
+#endif // PangoUtilities_h
index 0df547f..c71f041 100644 (file)
@@ -12,6 +12,7 @@ libfind_package(Pango Freetype)
 
 # Use pkg-config to get hints about paths
 libfind_pkg_check_modules(Pango_PKGCONF pango)
+libfind_pkg_check_modules(Pango_Cairo_PKGCONF pango)
 
 # Include dir
 find_path(Pango_INCLUDE_DIR
@@ -20,12 +21,23 @@ find_path(Pango_INCLUDE_DIR
   PATH_SUFFIXES pango-1.0
 )
 
+find_path(Pango_Cairo_INCLUDE_DIR
+  NAMES pango/pangocairo.h
+  PATHS ${Pango_Cairo_PKGCONF_INCLUDE_DIRS}
+  PATH_SUFFIXES pango-1.0
+)
+
 # Finally the library itself
 find_library(Pango_LIBRARY
   NAMES pango-1.0
   PATHS ${Pango_PKGCONF_LIBRARY_DIRS}
 )
 
+find_library(Pango_Cairo_LIBRARY
+  NAMES pangocairo-1.0
+  PATHS ${Pango_Cairo_PKGCONF_LIBRARY_DIRS}
+)
+
 # Set the include dir variables and the libraries and let libfind_process do the rest.
 # NOTE: Singular variables for this library, plural for libraries this this lib depends on.
 set(Pango_PROCESS_INCLUDES Pango_INCLUDE_DIR Freetype_INCLUDE_DIRS)