From 358db6050163de36095bacb47f87c6f9528b8491 Mon Sep 17 00:00:00 2001 From: habbisify Date: Thu, 18 Mar 2021 11:23:42 +0200 Subject: [PATCH] Implement convertUnit functionality. --- .../pdmodel/PDAbstractContentStream.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index a919475fbf6..088a760ff16 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1674,4 +1674,40 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea return glyphIdsAfterGsub; } + + /** + * Set the text rise value, i.e. move the baseline up or down. This is useful for drawing + * superscripts or subscripts. + * + * @param items + * @param unit_type + * @throws IllegalArgumentException + */ + public List convertUnit(List items, String unit_type) + { + float multiplier = 1; + if (unit_type == "mm") + { + multiplier = 1 / (10 * 2.54f) * 72; + } + else if (unit_type == "inch") + { + multiplier = 72; + } + else + { + throw new IllegalArgumentException( + "could not find the unit type: " + unit_type); + } + List items_new = new ArrayList(); + Iterator it = items.iterator(); + while(it.hasNext()) + { + Float item = it.next(); + item *= multiplier; + items_new.add(item); + } + + return items_new; + } }