[xep-support] Re: Feature request: "gradient background color"

From: Kevin Brown <kevin_at_ADDRESS_REMOVED>
Date: Sun May 13 2018 - 23:22:41 PDT

Had some extra time today.

I enhanced the XSL (it now is 2.0) and used PIs to carry various information
for creating a gradient.

I will wrap this into a new Cooltool with extra features, but you are free
to run with this and help or suggest better things.

 

Given this sample FO with both linear and radial gradient specified,
different colors, multiple colors, opacity and even gradeintTransform:

 

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
            xmlns:rx="http://www.renderx.com/XSL/Extensions">
            <fo:layout-master-set>
                        <fo:simple-page-master margin-top="1in"
margin-left="1in" margin-bottom="1in"
                                    margin-right="1in" page-width="8in"
page-height="11in" master-name="first">
                                    <fo:region-body margin-top="0pt"/>
                                    <fo:region-before extent="0pt"/>
                                    <fo:region-after extent="0pt"/>
                        </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="first">
                        <fo:flow flow-name="xsl-region-body">
            <fo:block font-size="36pt" text-align="center">Sample
Gradients</fo:block>
                            <fo:block space-before="12pt"></fo:block>
                            <?xep-gradient grad1?>
            <?xep-gradient-type grad1,linearGradient?>
            <?xep-gradient-color grad1,0,orange,1?>
                            <?xep-gradient-color grad1,1,purple,1?>
                            <fo:block-container width="3in" height="1in"
background-color="red">
                                <fo:block line-height="1in"
text-align="center" font-size="24pt">Gradient</fo:block>
                            </fo:block-container>
                            <fo:block space-before="12pt"></fo:block>
                            <?xep-gradient grad5?>
                            <?xep-gradient-type grad5,linearGradient?>
                            <?xep-gradient-color grad5,0,lightblue,1?>
                            <?xep-gradient-color grad5,1,purple,1?>
                            <?xep-gradient-rotate grad5,45?>
                            <fo:block-container width="3in" height="1in"
background-color="red">
                                <fo:block line-height="1in"
text-align="center" font-size="24pt">Gradient</fo:block>
                            </fo:block-container>
                            <fo:block space-before="12pt"></fo:block>
                            <?xep-gradient grad2?>
                            <?xep-gradient-type grad2,linearGradient?>
                            <?xep-gradient-color grad2,0,red,1?>
                            <?xep-gradient-color grad2,1,yellow,1?>
                            <fo:block-container width="2in" height="2in"
background-color="red">
                                <fo:block line-height="2in"
text-align="center" font-size="24pt">Gradient</fo:block>
                            </fo:block-container>
                            <fo:block space-before="12pt"></fo:block>
                            <?xep-gradient grad3?>
                            <?xep-gradient-type grad3,radialGradient?>
                            <?xep-gradient-color grad3,0,green,1?>
                            <?xep-gradient-color grad3,1,yellow,1?>
                            <fo:block-container width="2in" height="2in"
background-color="red">
                                <fo:block line-height="2in"
text-align="center" font-size="24pt">Gradient</fo:block>
                            </fo:block-container>
                            <fo:block space-before="12pt"></fo:block>
                            <?xep-gradient grad4?>
                            <?xep-gradient-type grad4,radialGradient?>
                            <?xep-gradient-color grad4,0,orange,1?>
                            <?xep-gradient-color grad4,.33,green,0.5?>
                            <?xep-gradient-color grad4,.66,yellow,0.7?>
                            <?xep-gradient-color grad4,1,red,0?>
                            <fo:block-container width="2in" height="2in"
background-color="red">
                                <fo:block line-height="2in"
text-align="center" font-size="24pt">Gradient</fo:block>
                            </fo:block-container>
                        </fo:flow>
            </fo:page-sequence>
</fo:root>

 

Apply the following XSL to the resulting XEPOUT from that FO:

<?xml version="1.0" encoding="UTF-8"?>
        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:exslt="http://exslt.org/common"
            xmlns:xep="http://www.renderx.com/XEP/xep" version="2.0">
            <xsl:template match="xep:page">
                <xep:page>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates select="*"/>
                </xep:page>
            </xsl:template>
            <!-- Change rectangle to SVG-->
            <xsl:template
match="xep:rectangle[preceding-sibling::*[1][name()='xep:rgb-color'][@red='1
.0']]">
                <xsl:variable name="gradname"
select="string(preceding::processing-instruction('xep-gradient')[1])"/>
                <xsl:variable name="gradtype"
select="substring-after(preceding::processing-instruction('xep-gradient-type
')[1],concat($gradname,','))"/>
                <xsl:variable name="xepwidth" select="number(@x-till -
@x-from)"/>
                <xsl:variable name="xepheight" select="number(@y-till -
@y-from)"/>
                <xsl:variable name="width" select="concat(number((@x-till -
@x-from) div 72000),'in')"/>
                <xsl:variable name="height" select="concat(number((@y-till -
@y-from) div 72000),'in')"/>
                <xsl:variable name="svgnode">
                    <svg width='{$width}' height='{$height}'>
                       <defs>
                           <xsl:element name="{$gradtype}">
                                <xsl:attribute name="id">
                                    <xsl:value-of select="$gradname"/>
                                </xsl:attribute>
                               <xsl:if
test="contains(string(preceding::processing-instruction('xep-gradient-rotate
')[1]),$gradname)">
                                   <xsl:attribute name="gradientTransform">
                                       <xsl:text>rotate(</xsl:text>
                                       <xsl:value-of
select="substring-after(string(preceding::processing-instruction('xep-gradie
nt-rotate')[1]),concat($gradname,','))"/>
                                       <xsl:text>)</xsl:text>
                                   </xsl:attribute>
                                </xsl:if>
                               <xsl:for-each
select="preceding::processing-instruction('xep-gradient-color')[contains(.,$
gradname)]">
                                    <xsl:call-template name="stopcolor">
                                        <xsl:with-param name="colorspec"
select="substring-after(.,concat($gradname,','))"/>
                                    </xsl:call-template>
                                </xsl:for-each>
                            </xsl:element>
                       </defs>
                        <rect width='{$width}' height='{$height}'
fill='url(#{$gradname})'/>
                     </svg>
                </xsl:variable>
                <xsl:variable name="serialsvg">
                    <xsl:apply-templates select="$svgnode"
mode="serialize"/>
                </xsl:variable>
                <xep:image src="data:image/svg+xml;utf-8,{$serialsvg}"
                base="file:/C:Temp"
                type="image/svg+xml"
                x-from="{@x-from}"
                y-from="{@y-from}"
                scale-x="1.0"
                scale-y="1.0"
                width="{$xepwidth}"
                height="{$xepheight}"/>
            </xsl:template>
            <!-- remove red color -->
            <xsl:template match="xep:rgb-color[@red='1.0']"/>
            <!-- identity copy rules -->
            <xsl:template match="node() | @*">
                <xsl:copy>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates select="node()"/>
                </xsl:copy>
            </xsl:template>
            <xsl:template match="*" mode="serialize">
                <xsl:text>&lt;</xsl:text>
                <xsl:value-of select="name()"/>
                <xsl:choose>
                    <xsl:when test="name()='svg'">
                        <xsl:text> xmlns='http://www.w3.org/2000/svg'
</xsl:text>
                    </xsl:when>
                </xsl:choose>
                <xsl:apply-templates select="@*" mode="serialize" />
                <xsl:choose>
                    <xsl:when test="node()">
                        <xsl:text>&gt;</xsl:text>
                        <xsl:apply-templates mode="serialize" />
                        <xsl:text>&lt;/</xsl:text>
                        <xsl:value-of select="name()"/>
                        <xsl:text>&gt;</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text> /&gt;</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:template>
            <xsl:template match="@*" mode="serialize">
                <xsl:text> </xsl:text>
                <xsl:value-of select="name()"/>
                <xsl:text>="</xsl:text>
                <xsl:value-of select="."/>
                <xsl:text>"</xsl:text>
            </xsl:template>
            <xsl:template name="stopcolor">
                <xsl:param name="colorspec"/>
                <xsl:variable name="tokspec"
select="tokenize($colorspec,',')"/>
                <xsl:element name="stop">
                    <xsl:attribute name="offset">
                        <xsl:value-of select="$tokspec[1]"/>
                    </xsl:attribute>
                    <xsl:attribute name="stop-color">
                        <xsl:value-of select="$tokspec[2]"/>
                    </xsl:attribute>
                    <xsl:attribute name="stop-opacity">
                        <xsl:value-of select="$tokspec[3]"/>
                    </xsl:attribute>
                </xsl:element>
            </xsl:template>
            <xsl:template match="text()" mode="serialize">
                <xsl:value-of select="."/>
            </xsl:template>
        </xsl:stylesheet>

You get these pretty gradients:

 

 

 

From: Xep-support [mailto:xep-support-bounces@renderx.com] On Behalf Of
Kevin Brown
Sent: Friday, May 11, 2018 2:19 PM
To: 'RenderX Community Support List' <xep-support@renderx.com>
Subject: [xep-support] Re: Feature request: "gradient background color"

 

To give an example of making an easy, customizable solution … if you did
this in your FO:

 

<?xep-gradient radial-gradient(circle 100% at center, yellow, darkorange)?>
<fo:block-container width="3in" height="1in" background-color="red">
        <fo:block line-height="1in" text-align="center"
font-size="24pt">Gradient</fo:block>
</fo:block-container>

 

 

You would have this in XEPOUT:

 

<?xep-gradient radial-gradient(circle 100% at center, yellow, darkorange)?>
<xep:rgb-color red="1.0" green="0.0" blue="0.0"/>
<xep:rectangle x-from="72000" y-from="208800" x-till="288000"
y-till="280800"/>

 

You could then customize the solution I provided to read the PI
(xep-gradient, extracting gradient type and color from the XEPOUT and
process.

 

And if we re-wrote as 2.0, we could just use serialize() function to likely
get the result we need and not build it from strings.

 

Kevin

 

From: Xep-support [mailto:xep-support-bounces@renderx.com] On Behalf Of
Kevin Brown
Sent: Friday, May 11, 2018 1:46 PM
To: 'RenderX Community Support List' <xep-support@renderx.com
<mailto:xep-support@renderx.com> >
Subject: [xep-support] Re: Feature request: "gradient background color"

 

Note that I have used similar solution to do things like rounded corners or
gradient text which is really cool – as in given a marketing document’s
title, applying a gradient to the text.

 

Kevin

 

 

From: Xep-support [mailto:xep-support-bounces@renderx.com] On Behalf Of
Kevin Brown
Sent: Friday, May 11, 2018 1:36 PM
To: 'RenderX Community Support List' <xep-support@renderx.com
<mailto:xep-support@renderx.com> >
Subject: [xep-support] Re: Feature request: "gradient background color"

 

As promised and I didn’t even wait for the weekend.

Below is a simple example that could be expanded through PIs or Pinpoints or
other ways to carry the information you want for the gradient.

Right now it has fixed colors and is a linear gradient but you could easily
extend this.

I will probably do a new CoolTool and do just that.

 

What this does – it leverages the XEPOUT format to grab all red rectangles
(an area where you want the gradient --- you could use any color and trigger
on it).

It takes those red rectangles and uses their exact dimensions and replaces
them with a linear gradient SVG rectangle.

NOTE: All things with background colors could be done as they yield a
rectangle – could be a table-cell or block or block-container.

I just used block-containers in this sample.

 

Now, you could certainly expand all this … use a pinpoint or a PI to carry
the actual colors and type of gradient.

Or params in the XSL if you like.

 

Gradient-background.fo can be formatted to XEPOUT.

You would see this:

 

<xep:rgb-color red="1.0" green="0.0" blue="0.0"/>
<xep:rectangle x-from="72000" y-from="376800" x-till="360000"
y-till="520800"/>

 

A red rectangle.

 

That XEPOUT can be transformed with the attached identity-gradient.xsl XSL
to make a new XEPOUT.

That XEPOUT now has this:

       <xep:image src="data:image/svg+xml;utf-8,&lt;svg
xmlns=&#34;http://www.w3.org/2000/svg&#34; width=&#34;2in&#34;
height=&#34;2in&#34;&gt;&#xA; &lt;defs&gt;&#xA;
&lt;linearGradient id=&#34;myLinearGradient1&#34;&gt;&#xA;
&lt;stop offset=&#34;0&#34; stop-color=&#34;#11908d&#34;
stop-opacity=&#34;1&#34;/&gt;&#xA; &lt;stop
offset=&#34;1&#34; stop-color=&#34;#646452&#34;
stop-opacity=&#34;1&#34;/&gt;&#xA;
&lt;/linearGradient&gt;&#xA; &lt;/defs&gt;&#xA;
&lt;rect width=&#34;&#xA; 2in&#34; height=&#34;2in&#34;
fill=&#34;url(#myLinearGradient1)&#34;/&gt;&#xA;
&lt;/svg&gt;&#xA; " base="file:/C:Temp"
type="image/svg+xml" x-from="72000" y-from="532800" scale-x="1.0"
scale-y="1.0" width="144000" height="144000"/>

Which changes the rectangle to a UTF-8 encoded inline SVG image.
NOTE – if you use XSL 2.0 you could likely do this easier than I did in the
XSL, feel free to improve!

 

The result:

 

Problem solved. No custom development required. A simple solution in a
toolchain.

 

Kevin Brown

(650) 327-1000 Direct

(650) 328-8008 Fax

(925) 395-1772 Mobile

skype:kbrown01

kevin@renderx.com <mailto:kevin@renderx.com>

sales@renderx.com <mailto:sales@renderx.com>

http://www.renderx.com <http://www.renderx.com/>

 

 

 

From: Xep-support [mailto:xep-support-bounces@renderx.com] On Behalf Of
Kevin Brown
Sent: Friday, May 11, 2018 11:41 AM
To: 'RenderX Community Support List' <xep-support@renderx.com
<mailto:xep-support@renderx.com> >
Subject: [xep-support] Re: Feature request: "gradient background color"

 

We are looking at the solution within the context of our development path
and demand.

If there is other folks on this list that would like to see such a feature,
please let us know.

 

In the meantime, I believe this could be solved through XEPOUT manipulation.

I did a similar solution for background behind rx:flow-section.

I will need to examine and get back to you after the weekend.

 

Kevin Brown

(650) 327-1000 Direct

(650) 328-8008 Fax

(925) 395-1772 Mobile

skype:kbrown01

kevin@renderx.com <mailto:kevin@renderx.com>

sales@renderx.com <mailto:sales@renderx.com>

http://www.renderx.com <http://www.renderx.com/>

 

 

 

From: Xep-support [mailto:xep-support-bounces@renderx.com] On Behalf Of
Kirch Fritz
Sent: Friday, May 11, 2018 5:23 AM
To: 'RenderX Community Support List' <xep-support@renderx.com
<mailto:xep-support@renderx.com> >
Subject: [xep-support] Feature request: "gradient background color"

 

Dear XEP-Support team,

currently I am looking for a solution to specify gradient background images
to <fo:block> areas.
At antennahouse’s webpages I found this:
 
<https://www.antennahouse.com/antenna1/wp-content/uploads/2018/02/background
-image-gradient-1.pdf>
https://www.antennahouse.com/antenna1/wp-content/uploads/2018/02/background-
image-gradient-1.pdf

My question:
Can RenderX deliver a comparable functionality as described in that
antennahouse-PDF?
In what time frame can RenderX realize these features and what will be the
prize for this?

I think this would be a nice feature to increase the attractivity of RenderX
products.

Kind regards
Freundliche Grüße

Friedrich Kirch

IT2media
Nuremberg, Germany

 

_______________________________________________
(*) To unsubscribe, please visit http://lists.renderx.com/mailman/options/xep-support
(*) By using the Service, you expressly agree to these Terms of Service http://w
ww.renderx.com/terms-of-service.html

image001.png image002.png
Received on Sun May 13 23:21:18 2018

This archive was generated by hypermail 2.1.8 : Sun May 13 2018 - 23:21:30 PDT