Author: tilman
Date: Fri Jul 3 11:49:57 2026
New Revision: 1935832
Log:
PDFBOX-4951: add interfaces for glyph layout and storage for glphs and
positions, by Volker Kunert
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ContentStreamForGlyphLayoutInterface.java
(contents, props changed)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphLayoutProcessorInterface.java
(contents, props changed)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphsAndPositions.java
(contents, props changed)
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ContentStreamForGlyphLayoutInterface.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ContentStreamForGlyphLayoutInterface.java
Fri Jul 3 11:49:57 2026 (r1935832)
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel;
+
+import java.io.IOException;
+
+public interface ContentStreamForGlyphLayoutInterface
+{
+
+ /**
+ * Show the given glyphs at the specified positions
+ *
+ * @param glyphsAndPositions List of glyphs and positions
+ * @throws IOException if an IO error occurs
+ */
+ void showGlyphsWithPositioning(GlyphsAndPositions glyphsAndPositions)
throws IOException;
+
+ /**
+ * Shows the glyphs for the given glyph codes
+ *
+ * @param glyphCodes Array of glyph codes of the content font
+ * @throws IOException if an I/O exception occurs
+ */
+ void showGlyphCodes(int[] glyphCodes) throws IOException;
+
+ /**
+ * Set the text rise value, i.e. move the baseline up or down. This is
useful for drawing
+ * superscripts or subscripts.
+ *
+ * @param rise Specifies the distance, in unscaled text space units, to
move the baseline up or
+ * down from its default location. 0 restores the default location.
+ * @throws IOException If the content stream could not be written.
+ */
+ void setTextRise(float rise) throws IOException;
+}
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphLayoutProcessorInterface.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphLayoutProcessorInterface.java
Fri Jul 3 11:49:57 2026 (r1935832)
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel;
+
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
+
+import java.io.IOException;
+
+public interface GlyphLayoutProcessorInterface
+{
+
+ /**
+ * Checks if the font is supported
+ *
+ * @param font to be checked
+ * @return true if glyph layout is supported for this font and this font
is a PDType0Font
+ */
+ boolean supportsFont(PDFont font);
+
+ /**
+ * Shows a text using glyph positioning (if needed)
+ *
+ * @param contentStream the content stream
+ * @param font to be used
+ * @param fontSize font size
+ * @param text text to show
+ * @throws IOException if an I/O exception occurs
+ * @throws IllegalArgumentException if glyphs are missing
+ */
+ void showText(ContentStreamForGlyphLayoutInterface contentStream,
PDType0Font font, float fontSize, String text) throws IOException;
+}
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphsAndPositions.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/GlyphsAndPositions.java
Fri Jul 3 11:49:57 2026 (r1935832)
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ * Stores sublists of glyphs and positions in a list
+ */
+public class GlyphsAndPositions
+{
+
+ private final ArrayList<Object> list = new ArrayList<>();
+
+ /**
+ * Sublist to store adjacent glyphs
+ */
+ public static class GlyphSubList extends ArrayList<Integer>
+ {
+ }
+
+ /**
+ * Adds a glyph
+ *
+ * @param glyph to be added
+ */
+ public void add(Integer glyph)
+ {
+ Object last = !list.isEmpty() ? list.get(list.size() - 1) : null;
+ GlyphSubList glyphSubList;
+ if (!(last instanceof GlyphSubList))
+ {
+ glyphSubList = new GlyphSubList();
+ list.add(glyphSubList);
+ }
+ else
+ {
+ glyphSubList = (GlyphSubList) last;
+ }
+ glyphSubList.add(glyph);
+ }
+
+ /**
+ * Add a position
+ *
+ * @param position to be added
+ */
+ public void add(Float position)
+ {
+ list.add(position);
+ }
+
+ /**
+ * Checks if the list is empty
+ *
+ * @return true if it is empty
+ */
+ public boolean isEmpty()
+ {
+ return list.isEmpty();
+ }
+
+ /**
+ * Clears the list
+ */
+ public void clear()
+ {
+ list.clear();
+ }
+
+ /**
+ * Converts GlyphsAndPositions to an array of objects (GlyphSubList and
Float)
+ *
+ * @return the array
+ */
+ public Object[] toArray()
+ {
+ return Collections.unmodifiableList(list).toArray();
+ }
+}