1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<!--
25	For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
26-->
27<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
28	<!-- DPI (dots per inch) the standard resolution of given pictures (necessary for the conversion of 'cm' into 'pixel')
29		 Although many pictures have a 96 dpi resolution, a higher resoltion give better results for common browsers -->
30	<xsl:param name="dpi" select="111"/>
31	<xsl:param name="centimeter-in-mm" select="10"/>
32	<xsl:param name="inch-in-mm" select="25.4"/>
33	<xsl:param name="didot-point-in-mm" select="0.376065"/>
34	<xsl:param name="pica-in-mm" select="4.2333333"/>
35	<xsl:param name="point-in-mm" select="0.3527778"/>
36	<xsl:param name="twip-in-mm" select="0.017636684"/>
37	<xsl:param name="pixel-in-mm" select="$inch-in-mm div $dpi"/>
38	<!-- ***** MEASUREMENT CONVERSIONS *****
39	  PARAM 'value'
40		The measure to be converted.
41		The current measure is judged by a substring (e.g. 'mm', 'cm', 'in', 'pica'...)
42		directly added to the number.
43
44	  PARAM 'rounding-factor'
45		Is used for the rounding of decimal places.
46		The parameter number is the product of 1 and some '10', where
47		every zero represents a decimal place.
48
49		For example, providing as parameter:
50			<xsl:param name="rounding-factor" select="10000" />
51		Gives by default four decimal places.
52
53		To round two decimal places, basically the following is done:
54			<xsl:value-of select="round(100 * value) div 100"/>
55
56	  RETURN    The converted number, by default rounded to four decimal places.
57				In case the input measure could not be matched the same value is
58				returned and a warning message is written out.
59
60
61
62	 MEASURE LIST:
63	 * 1 milimeter (mm), the basic measure
64
65	 * 1 centimeter (cm) = 10 mm
66
67	 * 1 inch (in) = 25.4 mm
68		While the English have already seen the light (read: the metric system), the US
69		remains loyal to this medieval system.
70
71	 * 1 point (pt) = 0.35277777.. mm
72		Sometimes called PostScript point (ppt), as when Adobe created PostScript, they added their own system of points.
73		There are exactly 72 PostScript points in 1 inch.
74
75	 * 1 twip = twentieth of a (PostScript) point
76		A twip (twentieth of a point) is a 1/20th of a PostScript point, a traditional measure in printing.
77
78	 * 1 didot point (dpt) = 0.376065 mm
79		Didot point after the French typographer Firmin Didot (1764-1836).
80
81		More details under
82		http://www.unc.edu/~rowlett/units/dictP.html:
83		"A unit of length used by typographers and printers. When printing was done
84		from hand-set metal type, one point represented the smallest element of type
85		that could be handled, roughly 1/64 inch. Eventually, the point was standardized
86		in Britain and America as exactly 1/72.27 = 0.013 837 inch, which is
87		about 0.35 mm (351.46 micrometers). In continental Europe, typographers
88		traditionally used a slightly larger point of 0.014 83 inch (about
89		1/72 pouce, 0.377 mm, or roughly 1/67 English inch), called a Didot point
90		after the French typographer Firmin Didot (1764-1836). In the U.S.,
91		Adobe software defines the point to be exactly 1/72 inch (0.013 888 9 inch
92		or 0.352 777 8 millimeters) and TeX software uses a slightly smaller point
93		of 0.351 459 8035 mm. The German standards agency DIN has proposed that
94		all these units be replaced by multiples of 0.25 millimeters (1/101.6 inch).
95
96	 * 1 pica = 4.233333 mm
97		1/6 inch or 12 points
98
99	 * 1 pixel (px) = 0.26458333.. mm   (relative to 'DPI', here: 96 dpi)
100		Most pictures have the 96 dpi resolution, but the dpi variable may vary by stylesheet parameter
101
102
103	-->
104	<!-- changing measure to mm -->
105	<xsl:template name="convert2mm">
106		<xsl:param name="value"/>
107		<xsl:param name="rounding-factor" select="10000"/>
108		<xsl:choose>
109			<xsl:when test="contains($value, 'mm')">
110				<xsl:value-of select="substring-before($value, 'mm')"/>
111			</xsl:when>
112			<xsl:when test="contains($value, 'cm')">
113				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm' ) * $centimeter-in-mm)) div $rounding-factor"/>
114			</xsl:when>
115			<xsl:when test="contains($value, 'in')">
116				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in' ) * $inch-in-mm)) div $rounding-factor"/>
117			</xsl:when>
118			<xsl:when test="contains($value, 'pt')">
119				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') * $point-in-mm)) div $rounding-factor"/>
120			</xsl:when>
121			<xsl:when test="contains($value, 'twip')">
122				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') * $twip-in-mm)) div $rounding-factor"/>
123			</xsl:when>
124			<xsl:when test="contains($value, 'dpt')">
125				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') * $didot-point-in-mm)) div $rounding-factor"/>
126			</xsl:when>
127			<xsl:when test="contains($value, 'pica')">
128				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') * $pica-in-mm)) div $rounding-factor"/>
129			</xsl:when>
130			<xsl:when test="contains($value, 'px')">
131				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') * $pixel-in-mm)) div $rounding-factor"/>
132			</xsl:when>
133			<xsl:otherwise>
134				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'mm'!</xsl:message>
135				<xsl:value-of select="$value"/>
136			</xsl:otherwise>
137		</xsl:choose>
138	</xsl:template>
139	<!-- changing measure to cm -->
140	<xsl:template name="convert2cm">
141		<xsl:param name="value"/>
142		<xsl:param name="rounding-factor" select="10000"/>
143		<xsl:choose>
144			<xsl:when test="contains($value, 'mm')">
145				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $centimeter-in-mm)) div $rounding-factor"/>
146			</xsl:when>
147			<xsl:when test="contains($value, 'cm')">
148				<xsl:value-of select="substring-before($value, 'cm')"/>
149			</xsl:when>
150			<xsl:when test="contains($value, 'in')">
151				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in') div $centimeter-in-mm * $inch-in-mm)) div $rounding-factor"/>
152			</xsl:when>
153			<xsl:when test="contains($value, 'pt')">
154				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') div $centimeter-in-mm * $point-in-mm)) div $rounding-factor"/>
155			</xsl:when>
156			<xsl:when test="contains($value, 'dpt')">
157				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') div $centimeter-in-mm * $didot-point-in-mm)) div $rounding-factor"/>
158			</xsl:when>
159			<xsl:when test="contains($value, 'pica')">
160				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') div $centimeter-in-mm * $pica-in-mm)) div $rounding-factor"/>
161			</xsl:when>
162			<xsl:when test="contains($value, 'twip')">
163				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') div $centimeter-in-mm * $twip-in-mm)) div $rounding-factor"/>
164			</xsl:when>
165			<xsl:when test="contains($value, 'px')">
166				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $centimeter-in-mm * $pixel-in-mm)) div $rounding-factor"/>
167			</xsl:when>
168			<xsl:otherwise>
169				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'cm'!</xsl:message>
170				<xsl:value-of select="$value"/>
171			</xsl:otherwise>
172		</xsl:choose>
173	</xsl:template>
174	<!-- changing measure to inch (cp. section comment) -->
175	<xsl:template name="convert2in">
176		<xsl:param name="value"/>
177		<xsl:param name="rounding-factor" select="10000"/>
178		<xsl:choose>
179			<xsl:when test="contains($value, 'mm')">
180				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $inch-in-mm)) div $rounding-factor"/>
181			</xsl:when>
182			<xsl:when test="contains($value, 'cm')">
183				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm') div $inch-in-mm * $centimeter-in-mm)) div $rounding-factor"/>
184			</xsl:when>
185			<xsl:when test="contains($value, 'in')">
186				<xsl:value-of select="substring-before($value, 'in')"/>
187			</xsl:when>
188			<xsl:when test="contains($value, 'pt')">
189				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') div $inch-in-mm * $point-in-mm)) div $rounding-factor"/>
190			</xsl:when>
191			<xsl:when test="contains($value, 'dpt')">
192				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') div $inch-in-mm * $didot-point-in-mm)) div $rounding-factor"/>
193			</xsl:when>
194			<xsl:when test="contains($value, 'pica')">
195				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') div $inch-in-mm * $pica-in-mm)) div $rounding-factor"/>
196			</xsl:when>
197			<xsl:when test="contains($value, 'twip')">
198				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') div $inch-in-mm * $twip-in-mm)) div $rounding-factor"/>
199			</xsl:when>
200			<xsl:when test="contains($value, 'px')">
201				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $inch-in-mm * $pixel-in-mm)) div $rounding-factor"/>
202			</xsl:when>
203			<xsl:otherwise>
204				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'in'!</xsl:message>
205				<xsl:value-of select="$value"/>
206			</xsl:otherwise>
207		</xsl:choose>
208	</xsl:template>
209	<!-- changing measure to dpt (cp. section comment) -->
210	<xsl:template name="convert2dpt">
211		<xsl:param name="value"/>
212		<xsl:param name="rounding-factor" select="10000"/>
213		<xsl:choose>
214			<xsl:when test="contains($value, 'mm')">
215				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $didot-point-in-mm)) div $rounding-factor"/>
216			</xsl:when>
217			<xsl:when test="contains($value, 'cm')">
218				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm') div $didot-point-in-mm * $centimeter-in-mm)) div $rounding-factor"/>
219			</xsl:when>
220			<xsl:when test="contains($value, 'in')">
221				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in') div $didot-point-in-mm * $inch-in-mm)) div $rounding-factor"/>
222			</xsl:when>
223			<xsl:when test="contains($value, 'pt')">
224				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') div $didot-point-in-mm * $point-in-mm)) div $rounding-factor"/>
225			</xsl:when>
226			<xsl:when test="contains($value, 'dpt')">
227				<xsl:value-of select="substring-before($value, 'dpt')"/>
228			</xsl:when>
229			<xsl:when test="contains($value, 'pica')">
230				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') div $didot-point-in-mm * $pica-in-mm)) div $rounding-factor"/>
231			</xsl:when>
232			<xsl:when test="contains($value, 'twip')">
233				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') div $didot-point-in-mm * $twip-in-mm)) div $rounding-factor"/>
234			</xsl:when>
235			<xsl:when test="contains($value, 'px')">
236				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $didot-point-in-mm * $pixel-in-mm)) div $rounding-factor"/>
237			</xsl:when>
238			<xsl:otherwise>
239				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'dpt'!</xsl:message>
240				<xsl:value-of select="$value"/>
241			</xsl:otherwise>
242		</xsl:choose>
243	</xsl:template>
244	<!-- changing measure to pica (cp. section comment) -->
245	<xsl:template name="convert2pica">
246		<xsl:param name="value"/>
247		<xsl:param name="rounding-factor" select="10000"/>
248		<xsl:choose>
249			<xsl:when test="contains($value, 'mm')">
250				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $pica-in-mm)) div $rounding-factor"/>
251			</xsl:when>
252			<xsl:when test="contains($value, 'cm')">
253				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm') div $pica-in-mm * $centimeter-in-mm)) div $rounding-factor"/>
254			</xsl:when>
255			<xsl:when test="contains($value, 'in')">
256				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in') div $pica-in-mm * $inch-in-mm)) div $rounding-factor"/>
257			</xsl:when>
258			<xsl:when test="contains($value, 'pt')">
259				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') div $pica-in-mm * $point-in-mm)) div $rounding-factor"/>
260			</xsl:when>
261			<xsl:when test="contains($value, 'dpt')">
262				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') div $pica-in-mm * $didot-point-in-mm)) div $rounding-factor"/>
263			</xsl:when>
264			<xsl:when test="contains($value, 'pica')">
265				<xsl:value-of select="substring-before($value, 'pica')"/>
266			</xsl:when>
267			<xsl:when test="contains($value, 'twip')">
268				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') div $pica-in-mm * $twip-in-mm)) div $rounding-factor"/>
269			</xsl:when>
270			<xsl:when test="contains($value, 'px')">
271				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $pica-in-mm * $pixel-in-mm)) div $rounding-factor"/>
272			</xsl:when>
273			<xsl:otherwise>
274				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'pica'!</xsl:message>
275				<xsl:value-of select="$value"/>
276			</xsl:otherwise>
277		</xsl:choose>
278	</xsl:template>
279	<!-- changing measure to pt (cp. section comment) -->
280	<xsl:template name="convert2pt">
281		<xsl:param name="value"/>
282		<xsl:param name="rounding-factor" select="10000"/>
283		<xsl:choose>
284			<xsl:when test="contains($value, 'mm')">
285				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $point-in-mm)) div $rounding-factor"/>
286			</xsl:when>
287			<xsl:when test="contains($value, 'cm')">
288				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm') div $point-in-mm * $centimeter-in-mm)) div $rounding-factor"/>
289			</xsl:when>
290			<xsl:when test="contains($value, 'in')">
291				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in') div $point-in-mm * $inch-in-mm)) div $rounding-factor"/>
292			</xsl:when>
293			<xsl:when test="contains($value, 'pt')">
294				<xsl:value-of select="substring-before($value, 'pt')"/>
295			</xsl:when>
296			<xsl:when test="contains($value, 'dpt')">
297				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') div $point-in-mm * $didot-point-in-mm)) div $rounding-factor"/>
298			</xsl:when>
299			<xsl:when test="contains($value, 'pica')">
300				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') div $point-in-mm * $pica-in-mm)) div $rounding-factor"/>
301			</xsl:when>
302			<xsl:when test="contains($value, 'twip')">
303				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'twip') div $point-in-mm * $twip-in-mm)) div $rounding-factor"/>
304			</xsl:when>
305			<xsl:when test="contains($value, 'px')">
306				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $point-in-mm * $pixel-in-mm)) div $rounding-factor"/>
307			</xsl:when>
308			<xsl:otherwise>
309				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'pt'!</xsl:message>
310				<xsl:value-of select="$value"/>
311			</xsl:otherwise>
312		</xsl:choose>
313	</xsl:template>
314	<!-- changing measure to twip (cp. section comment) -->
315	<xsl:template name="convert2twip">
316		<xsl:param name="value"/>
317		<xsl:param name="rounding-factor" select="10000"/>
318		<xsl:choose>
319			<xsl:when test="contains($value, 'mm')">
320				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'mm') div $twip-in-mm)) div $rounding-factor"/>
321			</xsl:when>
322			<xsl:when test="contains($value, 'cm')">
323				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'cm') div $twip-in-mm * $centimeter-in-mm)) div $rounding-factor"/>
324			</xsl:when>
325			<xsl:when test="contains($value, 'in')">
326				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'in') div $twip-in-mm * $inch-in-mm)) div $rounding-factor"/>
327			</xsl:when>
328			<xsl:when test="contains($value, 'pt')">
329				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pt') div $twip-in-mm * $point-in-mm)) div $rounding-factor"/>
330			</xsl:when>
331			<xsl:when test="contains($value, 'dpt')">
332				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'dpt') div $twip-in-mm * $didot-point-in-mm)) div $rounding-factor"/>
333			</xsl:when>
334			<xsl:when test="contains($value, 'pica')">
335				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'pica') div $twip-in-mm * $pica-in-mm)) div $rounding-factor"/>
336			</xsl:when>
337			<xsl:when test="contains($value, 'twip')">
338				<xsl:value-of select="substring-before($value, 'twip')"/>
339			</xsl:when>
340			<xsl:when test="contains($value, 'px')">
341				<xsl:value-of select="round($rounding-factor * number(substring-before($value, 'px') div $twip-in-mm * $pixel-in-mm)) div $rounding-factor"/>
342			</xsl:when>
343			<xsl:otherwise>
344				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'twip'!</xsl:message>
345				<xsl:value-of select="$value"/>
346			</xsl:otherwise>
347		</xsl:choose>
348	</xsl:template>
349	<!-- changing measure to pixel by via parameter provided dpi (dots per inch) standard factor (cp. section comment) -->
350	<xsl:template name="convert2px">
351		<xsl:param name="value"/>
352		<xsl:choose>
353			<xsl:when test="contains($value, 'mm')">
354				<xsl:value-of select="round(number(substring-before($value, 'mm')) div $pixel-in-mm)"/>
355			</xsl:when>
356			<xsl:when test="contains($value, 'cm')">
357				<xsl:value-of select="round(number(substring-before($value, 'cm')) div $pixel-in-mm * $centimeter-in-mm)"/>
358			</xsl:when>
359			<xsl:when test="contains($value, 'in')">
360				<xsl:value-of select="round(number(substring-before($value, 'in')) div $pixel-in-mm * $inch-in-mm)"/>
361			</xsl:when>
362			<xsl:when test="contains($value, 'pt')">
363				<xsl:value-of select="round(number(substring-before($value, 'pt')) div $pixel-in-mm * $point-in-mm)"/>
364			</xsl:when>
365			<xsl:when test="contains($value, 'dpt')">
366				<xsl:value-of select="round(number(substring-before($value, 'dpt')) div $pixel-in-mm * $didot-point-in-mm)"/>
367			</xsl:when>
368			<xsl:when test="contains($value, 'pica')">
369				<xsl:value-of select="round(number(substring-before($value, 'pica')) div $pixel-in-mm * $pica-in-mm)"/>
370			</xsl:when>
371			<xsl:when test="contains($value, 'twip')">
372				<xsl:value-of select="round(number(substring-before($value, 'twip')) div $pixel-in-mm * $twip-in-mm)"/>
373			</xsl:when>
374			<xsl:when test="contains($value, 'px')">
375				<xsl:value-of select="$value"/>
376			</xsl:when>
377			<xsl:otherwise>
378				<xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'px'!</xsl:message>
379				<xsl:value-of select="$value"/>
380			</xsl:otherwise>
381		</xsl:choose>
382	</xsl:template>
383</xsl:stylesheet>
384