[cairo-commit] 3 commits - src/cairo-svg-glyph-render.c src/make-cairo-def.sh test/cairo-svg-test-palette.ttx test/ft-svg-render-palette.c test/meson.build test/reference test/svg

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 26 01:12:22 UTC 2023


 src/cairo-svg-glyph-render.c                 |    2 
 src/make-cairo-def.sh                        |    5 
 test/cairo-svg-test-palette.ttx              |  226 +++++++++++++++++++++++++++
 test/ft-svg-render-palette.c                 |   89 ++++++++++
 test/meson.build                             |    4 
 test/reference/ft-svg-render-palette.ref.png |binary
 test/svg/palette.0.color0.svg                |    4 
 test/svg/palette.1.color1.svg                |    4 
 8 files changed, 330 insertions(+), 4 deletions(-)

New commits:
commit 0151a67e33f7c96645ae581b31861780b531a7e1
Merge: 9ed9cfcf3 b68583ee5
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Jan 26 01:12:20 2023 +0000

    Merge branch 'svg-font-palette' into 'master'
    
    Add svg font test for custom palette colors
    
    See merge request cairo/cairo!418

commit b68583ee54324f2f52642778d6c5eee880b7dc38
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jan 21 17:45:00 2023 +1030

    Add test for SVG font palettes

diff --git a/src/cairo-svg-glyph-render.c b/src/cairo-svg-glyph-render.c
index 96094cbd2..8cc418f5e 100644
--- a/src/cairo-svg-glyph-render.c
+++ b/src/cairo-svg-glyph-render.c
@@ -795,7 +795,7 @@ get_color (cairo_svg_glyph_render_t *svg_render,
         if (end == s)
             return FALSE;
 
-        if (svg_render->palette && entry > 0 && entry < svg_render->num_palette_entries) {
+        if (svg_render->palette && entry >= 0 && entry < svg_render->num_palette_entries) {
             FT_Color *palette_color = &svg_render->palette[entry];
             color->type = RGB;
             color->red = palette_color->red / 255.0;
diff --git a/test/cairo-svg-test-palette.ttx b/test/cairo-svg-test-palette.ttx
new file mode 100644
index 000000000..0ee1a3977
--- /dev/null
+++ b/test/cairo-svg-test-palette.ttx
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.38">
+
+  <GlyphOrder>
+    <!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
+    <GlyphID id="0" name=".notdef"/>
+    <GlyphID id="1" name="zero"/>
+    <GlyphID id="2" name="one"/>
+  </GlyphOrder>
+
+  <head>
+    <!-- Most of this table will be recalculated by the compiler -->
+    <tableVersion value="1.0"/>
+    <fontRevision value="1.0"/>
+    <checkSumAdjustment value="0xcb6df82"/>
+    <magicNumber value="0x5f0f3cf5"/>
+    <flags value="00000000 00000011"/>
+    <unitsPerEm value="1000"/>
+    <created value="Wed Jun 15 00:00:00 2022"/>
+    <modified value="Sat Jan 21 05:46:29 2023"/>
+    <xMin value="0"/>
+    <yMin value="0"/>
+    <xMax value="1000"/>
+    <yMax value="1000"/>
+    <macStyle value="00000000 00000000"/>
+    <lowestRecPPEM value="6"/>
+    <fontDirectionHint value="2"/>
+    <indexToLocFormat value="0"/>
+    <glyphDataFormat value="0"/>
+  </head>
+
+  <hhea>
+    <tableVersion value="0x00010000"/>
+    <ascent value="1000"/>
+    <descent value="0"/>
+    <lineGap value="200"/>
+    <advanceWidthMax value="1100"/>
+    <minLeftSideBearing value="0"/>
+    <minRightSideBearing value="100"/>
+    <xMaxExtent value="1000"/>
+    <caretSlopeRise value="1"/>
+    <caretSlopeRun value="0"/>
+    <caretOffset value="0"/>
+    <reserved0 value="0"/>
+    <reserved1 value="0"/>
+    <reserved2 value="0"/>
+    <reserved3 value="0"/>
+    <metricDataFormat value="0"/>
+    <numberOfHMetrics value="1"/>
+  </hhea>
+
+  <maxp>
+    <!-- Most of this table will be recalculated by the compiler -->
+    <tableVersion value="0x10000"/>
+    <numGlyphs value="3"/>
+    <maxPoints value="4"/>
+    <maxContours value="1"/>
+    <maxCompositePoints value="0"/>
+    <maxCompositeContours value="0"/>
+    <maxZones value="1"/>
+    <maxTwilightPoints value="0"/>
+    <maxStorage value="0"/>
+    <maxFunctionDefs value="0"/>
+    <maxInstructionDefs value="0"/>
+    <maxStackElements value="256"/>
+    <maxSizeOfInstructions value="1"/>
+    <maxComponentElements value="0"/>
+    <maxComponentDepth value="0"/>
+  </maxp>
+
+  <OS_2>
+    <!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
+         will be recalculated by the compiler -->
+    <version value="3"/>
+    <xAvgCharWidth value="1000"/>
+    <usWeightClass value="400"/>
+    <usWidthClass value="5"/>
+    <fsType value="00000000 00000001"/>
+    <ySubscriptXSize value="600"/>
+    <ySubscriptYSize value="600"/>
+    <ySubscriptXOffset value="0"/>
+    <ySubscriptYOffset value="75"/>
+    <ySuperscriptXSize value="600"/>
+    <ySuperscriptYSize value="600"/>
+    <ySuperscriptXOffset value="0"/>
+    <ySuperscriptYOffset value="300"/>
+    <yStrikeoutSize value="0"/>
+    <yStrikeoutPosition value="300"/>
+    <sFamilyClass value="0"/>
+    <panose>
+      <bFamilyType value="0"/>
+      <bSerifStyle value="0"/>
+      <bWeight value="0"/>
+      <bProportion value="0"/>
+      <bContrast value="0"/>
+      <bStrokeVariation value="0"/>
+      <bArmStyle value="0"/>
+      <bLetterForm value="0"/>
+      <bMidline value="0"/>
+      <bXHeight value="0"/>
+    </panose>
+    <ulUnicodeRange1 value="00000000 00000000 00000000 00000001"/>
+    <ulUnicodeRange2 value="00000000 00000000 00000000 00000000"/>
+    <ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
+    <ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
+    <achVendID value="djr "/>
+    <fsSelection value="00000000 01000000"/>
+    <usFirstCharIndex value="48"/>
+    <usLastCharIndex value="49"/>
+    <sTypoAscender value="1000"/>
+    <sTypoDescender value="0"/>
+    <sTypoLineGap value="200"/>
+    <usWinAscent value="1000"/>
+    <usWinDescent value="300"/>
+    <ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
+    <ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
+    <sxHeight value="500"/>
+    <sCapHeight value="720"/>
+    <usDefaultChar value="0"/>
+    <usBreakChar value="32"/>
+    <usMaxContext value="3"/>
+  </OS_2>
+
+  <hmtx>
+    <mtx name=".notdef" width="1100" lsb="0"/>
+    <mtx name="one" width="1100" lsb="0"/>
+    <mtx name="zero" width="1100" lsb="0"/>
+  </hmtx>
+
+  <cmap>
+    <tableVersion version="0"/>
+    <cmap_format_4 platformID="0" platEncID="3" language="0">
+      <map code="0x30" name="zero"/><!-- DIGIT ZERO -->
+      <map code="0x31" name="one"/><!-- DIGIT ONE -->
+    </cmap_format_4>
+  </cmap>
+
+  <loca>
+    <!-- The 'loca' table will be calculated by the compiler -->
+  </loca>
+
+  <glyf>
+
+    <!-- The xMin, yMin, xMax and yMax values
+         will be recalculated by the compiler. -->
+
+    <TTGlyph name=".notdef"/><!-- contains no outline data -->
+
+    <TTGlyph name="one" xMin="0" yMin="0" xMax="1000" yMax="1000">
+      <contour>
+        <pt x="0" y="0" on="1"/>
+        <pt x="0" y="1000" on="1"/>
+        <pt x="1000" y="1000" on="1"/>
+        <pt x="1000" y="0" on="1"/>
+      </contour>
+      <instructions/>
+    </TTGlyph>
+
+    <TTGlyph name="zero" xMin="0" yMin="0" xMax="1000" yMax="1000">
+      <contour>
+        <pt x="0" y="0" on="1"/>
+        <pt x="0" y="1000" on="1"/>
+        <pt x="1000" y="1000" on="1"/>
+        <pt x="1000" y="0" on="1"/>
+      </contour>
+      <instructions/>
+    </TTGlyph>
+
+  </glyf>
+
+  <name>
+    <namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
+      Cairo Svg Test Palette
+    </namerecord>
+    <namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
+      Regular
+    </namerecord>
+    <namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
+      Cairo Svg Test Palette Regular
+    </namerecord>
+  </name>
+
+  <post>
+    <formatType value="3.0"/>
+    <italicAngle value="0.0"/>
+    <underlinePosition value="0"/>
+    <underlineThickness value="0"/>
+    <isFixedPitch value="0"/>
+    <minMemType42 value="0"/>
+    <maxMemType42 value="0"/>
+    <minMemType1 value="0"/>
+    <maxMemType1 value="0"/>
+  </post>
+
+  <CPAL>
+    <version value="0"/>
+    <numPaletteEntries value="2"/>
+    <palette index="0">
+      <color index="0" value="#C5A1D7FF"/>
+      <color index="1" value="#80DFC8FF"/>
+    </palette>
+    <palette index="1">
+      <color index="0" value="#6392A9FF"/>
+      <color index="1" value="#7896B3FF"/>
+    </palette>
+  </CPAL>
+
+  <SVG>
+    <svgDoc endGlyphID="0" startGlyphID="0">
+      <![CDATA[<svg xmlns="http://www.w3.org/2000/svg"></svg>]]>
+    </svgDoc>
+    <svgDoc endGlyphID="1" startGlyphID="1">
+      <![CDATA[<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
+  <rect x="100" y="-750" width="800" height="500"
+        fill="var(--color0, red)" />
+</svg>]]>
+    </svgDoc>
+    <svgDoc endGlyphID="2" startGlyphID="2">
+      <![CDATA[<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
+  <rect x="100" y="-750" width="800" height="500"
+        fill="var(--color1, blue)" />
+</svg>]]>
+    </svgDoc>
+  </SVG>
+
+</ttFont>
diff --git a/test/ft-svg-render-palette.c b/test/ft-svg-render-palette.c
new file mode 100644
index 000000000..3a01e4168
--- /dev/null
+++ b/test/ft-svg-render-palette.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright © 2023 Adrian Johnson
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Adrian Johnson <ajohnson at redneon.com>
+ */
+
+#include "cairo-test.h"
+#include <cairo-ft.h>
+
+#define FONT_SIZE 50
+#define MARGIN 5
+#define WIDTH  (FONT_SIZE*8 + MARGIN*9)
+#define HEIGHT (FONT_SIZE + MARGIN*2)
+
+#define FONT_FILE "cairo-svg-test-palette.ttf"
+
+#define TEXT "01"
+
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_test_status_t result;
+    cairo_font_options_t *font_options;
+
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    result = cairo_test_ft_select_font_from_file (cr, FONT_FILE);
+    if (result)
+        return result;
+
+    cairo_set_font_size (cr, FONT_SIZE);
+    cairo_move_to (cr, MARGIN, FONT_SIZE + MARGIN);
+
+    font_options = cairo_font_options_create ();
+
+    /* Default palette */
+    cairo_show_text (cr, TEXT);
+
+    /* Palette 1 */
+    cairo_font_options_set_color_palette (font_options, 1);
+    cairo_set_font_options (cr, font_options);
+    cairo_show_text (cr, TEXT);
+
+    /* Palette 0, override color 0 */
+    cairo_font_options_set_color_palette (font_options, 0);
+    cairo_font_options_set_custom_palette_color (font_options, 0, 1, 0, 1, 0.5);
+    cairo_set_font_options (cr, font_options);
+    cairo_show_text (cr, TEXT);
+
+    /* Palette 1, override color 1 */
+    cairo_font_options_set_color_palette (font_options, 1);
+    cairo_font_options_set_custom_palette_color (font_options, 1, 0, 1, 1, 0.5);
+    cairo_set_font_options (cr, font_options);
+    cairo_show_text (cr, TEXT);
+
+    cairo_font_options_destroy (font_options);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (ft_svg_render_palette,
+	    "Test cairo SVG font palettes",
+	    "svgrender", /* keywords */
+	    NULL, /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, draw)
diff --git a/test/meson.build b/test/meson.build
index de6b30c4f..275dd07d7 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -435,7 +435,8 @@ test_ft_svg_font_sources = [
 
 test_ft_svg_ttx_font_sources = [
   'ft-svg-cairo-logo.c',
-  'ft-svg-render.c'
+  'ft-svg-render.c',
+  'ft-svg-render-palette.c'
 ]
 
 test_gl_sources = [
@@ -534,6 +535,7 @@ test_ttx_fonts = [
   'cairo-svg-test-doc.ttx',
   'cairo-svg-test-fill.ttx',
   'cairo-svg-test-gradient.ttx',
+  'cairo-svg-test-palette.ttx',
   'cairo-svg-test-path.ttx',
   'cairo-svg-test-shapes.ttx',
   'cairo-svg-test-stroke.ttx',
diff --git a/test/reference/ft-svg-render-palette.ref.png b/test/reference/ft-svg-render-palette.ref.png
new file mode 100644
index 000000000..4a86f995b
Binary files /dev/null and b/test/reference/ft-svg-render-palette.ref.png differ
diff --git a/test/svg/palette.0.color0.svg b/test/svg/palette.0.color0.svg
new file mode 100644
index 000000000..650dca898
--- /dev/null
+++ b/test/svg/palette.0.color0.svg
@@ -0,0 +1,4 @@
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
+  <rect x="100" y="-750" width="800" height="500"
+        fill="var(--color0, red)" />
+</svg>
diff --git a/test/svg/palette.1.color1.svg b/test/svg/palette.1.color1.svg
new file mode 100644
index 000000000..2858b35ca
--- /dev/null
+++ b/test/svg/palette.1.color1.svg
@@ -0,0 +1,4 @@
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
+  <rect x="100" y="-750" width="800" height="500"
+        fill="var(--color1, blue)" />
+</svg>
commit 3cc9e198fdcb81ba26c47ecc95d05ed2ed72c534
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jan 21 17:16:27 2023 +1030

    Silence make-cairo-def.sh output
    
    This removes the following output:
    
      Generating src/cairo.def
      <stdin>:6:9: warning: #pragma once in main file
      <stdin>:4377:9: warning: #pragma once in main file

diff --git a/src/make-cairo-def.sh b/src/make-cairo-def.sh
index 664df0887..1a1f366e8 100644
--- a/src/make-cairo-def.sh
+++ b/src/make-cairo-def.sh
@@ -14,11 +14,12 @@ def_file="$1"
 cairo_features_h="$2"
 shift 2
 
-echo Generating $def_file
+#echo Generating $def_file
+
 (echo EXPORTS; \
  (cat $* || echo 'cairo_ERROR ()' ) | \
      egrep -v '^# *include' | \
-     ( cat "$cairo_features_h" - | cpp -D__cplusplus - || echo 'cairo_ERROR ()' ) | \
+     ( cat "$cairo_features_h" - | egrep -v '^#pragma' | cpp -D__cplusplus - || echo 'cairo_ERROR ()' ) | \
      egrep '^cairo_.* \(' | \
      sed -e 's/[ 	].*//' | \
      sort; \


More information about the cairo-commit mailing list