[Libreoffice-commits] dev-tools.git: scripts/tpconv.py
Miklos Vajna
vmiklos at suse.cz
Tue Jun 25 08:45:38 PDT 2013
scripts/tpconv.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
New commits:
commit 5b3b00828609e79a0603b99ddd6d64be3089f7e0
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Tue Jun 25 17:43:38 2013 +0200
import tpconv
Change-Id: Iba30b32fbbb9011f81dc80e3c36237b492a692b5
diff --git a/scripts/tpconv.py b/scripts/tpconv.py
new file mode 100755
index 0000000..a9e7bd1
--- /dev/null
+++ b/scripts/tpconv.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+import re
+import sys
+
+# Inspired by http://www.unitconversion.org/unit_converter/typography.html
+#
+# Additionally:
+# - supports UNO API's mm100 by default
+# - supports OOXML's EMU by default
+# - possible to extend
+
+conv = {
+ 'inch': 914400, # "there are 914,400 EMUs per inch"
+ 'point': 914400/72, # EMU / point
+ 'twip': 914400/72/20, # EMU / twip
+
+ 'm': 360*100000, # EMU / m
+ 'cm': 360*1000, # EMU is defined as 1/360,000 of a centimeter
+ 'mm': 360*100, # EMU / mm
+ 'mm100': 360, # EMU / mm100
+
+ 'emu': 1, # EMU / EMU
+ }
+
+def convert(amount, fro, to):
+ # convert to EMU
+ emu = amount * conv[re.sub("s$", "", fro)]
+ return emu / conv[re.sub("s$", "", to)]
+
+def main(args):
+ try:
+ amount = float(args[1])
+ fro = args[2]
+ to = args[4]
+ except IndexError:
+ print "usage: tpconv <amount> <from> in <to>"
+ return
+
+ print convert(amount, fro, to)
+
+if __name__ == '__main__':
+ main(sys.argv)
+
+# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
More information about the Libreoffice-commits
mailing list