[xep-support] New Installment of CoolTools - The Document Magnifier

From: Kevin Brown <kevin@renderx.com>
Date: Thu Aug 05 2010 - 16:53:35 PDT

Inspired by a recent post by Andy Black, I thought I would put together a
quick XSL for magnifying documents.

As with most CoolTools, this one relies on the XEP Intermediate Format -- we
call it XEPOUT. This format is documented here:

http://www.renderx.com/reference.html#IntermediateFormatSpecification

Remember -- there are many ways to get XEPOUT format. If you are running
from the command line, you can use xep.bat. Instead of specifying -pdf or
-ps for the output format, you just use -xep. So you might have something
like:

        xep.bat -xml myxml.xml -xsl myxsl.xsl -xep resultXEPOUT.xep

You can also get XEPOUT programmatically by setting the mimetype to
"application/xep". To format a modified XEPOUT, one just passes it back
through RenderX. For xep.bat, one would use:

        xep.bat -xep resultXEPOUT.xep -pdf mypdf.pdf

The document is not recomposed, only the final output is generated. As we
have shown in previous posts, you can do something like concatenate 1000s of
XEPOUT files together and create *huge* outputs as this final process from
XEPOUT to output (like PDF or PostScript) is very fast and takes very little
memory.

What is not documented at the above link is that there is also an XEPOUT
element called "xep:transform". It is not documented because while it is
built into the XEP Engine, there are no constructs in FO that currently
cause this element to be created. However, that doesn't stop us from telling
you about it nor using it in various projects we have created.

The "transform" element allows you to apply an affine matrix to all content
that follows this element. Since Andy is looking for scaling, we could
insert something like this in the XEPOUT document to scale the elements that
follow:

<xep:transform a="2" b="0" c="0" d="2" e="0" f="0"/>

Now, for the engineers out there, you would recall this is essentially (my
math is rusty but I think I have this one right!):

 | 2 0 0 |
 | 0 2 0 |
 | 0 0 1 |

Where the attributes are as following for an affine matrix:

 | a b 0 |
 | c d 0 |
 | e f 1 |

If the above <xep:transform> element inserted into the XEPOUT, it would
scale all content following it. The scale would be "2" (double the size)
because "a" and "d" (scale-x and scale-y respectively) are 2. You should
note that all elements work ... if you would like to see cool examples with
text that is rotated at arbitrary degrees and progressively scaled, just say
so. This element allows you to scale, translate and rotate.

Back to Andy's needs .... Now, we also need to change the page dimensions to
accommodate the size. We could write an easy identity-translate to operate
on XEPOUT and scale pages. By the way, choosing something like scale-x as
"5" and scale-y as "1" will turn you pages into silly putty, if that is what
you want, my kids thought that way funny when I did it!

*****************************************

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xep="http://www.renderx.com/XEP/xep" version="1.0">
    <xsl:param name="scale-x">3</xsl:param>
    <xsl:param name="scale-y">3</xsl:param>
    <xsl:template match="xep:document">
        <xsl:copy>
            <xsl:apply-templates select="@*" mode="identity-copy"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="xep:page">
        <xep:page>
            <!-- Scale the page width and height -->
            <xsl:attribute name="width">
                <xsl:value-of select="@width * $scale-x"/>
            </xsl:attribute>
            <xsl:attribute name="height">
                <xsl:value-of select="@height * $scale-y"/>
            </xsl:attribute>
            <xsl:attribute name="page-number">
                <xsl:value-of select="@page-number"/>
            </xsl:attribute>
            <xsl:attribute name="page-id">
                <xsl:value-of select="@page-id"/>
            </xsl:attribute>
            <!-- Insert Transform -->
            <xep:transform a="{$scale-x}" b="0" c="0" d="{$scale-y}" e="0"
f="0"/>
            <!-- Output Content -->
            <xsl:apply-templates select="*" mode="identity-copy"/>
        </xep:page>
    </xsl:template>

    <!-- identity copy rules -->
    <xsl:template match="node() | @*" mode="identity-copy"
name="identity-copy">
        <xsl:copy>
            <xsl:apply-templates select="@*" mode="identity-copy"/>
            <xsl:apply-templates select="node()" mode="identity-copy"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

*************************************************

Give it a try! If you would like a set of samples, I would be happy to share
but I promised a quick post to help Andy out and here it is.

Kevin Brown
RenderX Inc
kevin@renderx.com
650-327-1000

-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo@renderx.com from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/terms-of-service.html
Received on Thu Aug 5 17:26:57 2010

This archive was generated by hypermail 2.1.8 : Thu Aug 05 2010 - 17:26:58 PDT