From 5b3b00828609e79a0603b99ddd6d64be3089f7e0 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 25 Jun 2013 17:43:38 +0200 Subject: import tpconv Change-Id: Iba30b32fbbb9011f81dc80e3c36237b492a692b5 --- scripts/tpconv.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scripts/tpconv.py diff --git a/scripts/tpconv.py b/scripts/tpconv.py new file mode 100755 index 00000000..a9e7bd16 --- /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 in " + return + + print convert(amount, fro, to) + +if __name__ == '__main__': + main(sys.argv) + +# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: -- cgit v1.2.3