diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2013-06-25 17:43:38 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2013-06-25 17:45:19 +0200 |
commit | 5b3b00828609e79a0603b99ddd6d64be3089f7e0 (patch) | |
tree | e1381239e509139ef46010be4b933a595318140f | |
parent | cfd6f05e7f8e00897652d7c48218ab0f6cedf74e (diff) |
import tpconv
Change-Id: Iba30b32fbbb9011f81dc80e3c36237b492a692b5
-rwxr-xr-x | scripts/tpconv.py | 50 |
1 files changed, 50 insertions, 0 deletions
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 <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: |