You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2023/01/24 06:37:40 UTC

svn commit: r1906970 - in /pdfbox/trunk/fontbox/src: main/java/org/apache/fontbox/ttf/ test/java/org/apache/fontbox/ttf/

Author: lehmi
Date: Tue Jan 24 06:37:40 2023
New Revision: 1906970

URL: http://svn.apache.org/viewvc?rev=1906970&view=rev
Log:
PDFBOX-5560: add a method to provide the components of a composite glyph based on a proposal by Vladimir Plizga

Added:
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java   (with props)
Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java?rev=1906970&r1=1906969&r2=1906970&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeComp.java Tue Jan 24 06:37:40 2023
@@ -157,7 +157,7 @@ public class GlyfCompositeComp
      * 
      * @param idx the first index
      */
-    public void setFirstIndex(int idx)
+    protected void setFirstIndex(int idx)
     {
         firstIndex = idx;
     }
@@ -177,7 +177,7 @@ public class GlyfCompositeComp
      * 
      * @param idx the index of the first contour
      */
-    public void setFirstContour(int idx)
+    protected void setFirstContour(int idx)
     {
         firstContour = idx;
     }

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java?rev=1906970&r1=1906969&r2=1906970&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyfCompositeDescript.java Tue Jan 24 06:37:40 2023
@@ -20,6 +20,7 @@ package org.apache.fontbox.ttf;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -256,6 +257,16 @@ public class GlyfCompositeDescript exten
         return components.size();
     }
 
+    /**
+     * Gets a view to the composite components.
+     * 
+     * @return unmodifiable list of this composite glyph's {@linkplain GlyfCompositeComp components}
+     */
+    public List<GlyfCompositeComp> getComponents()
+    {
+        return Collections.unmodifiableList(components);
+    }
+
     private GlyfCompositeComp getCompositeComp(int i)
     {
         for (GlyfCompositeComp c : components)

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java?rev=1906970&r1=1906969&r2=1906970&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java Tue Jan 24 06:37:40 2023
@@ -84,14 +84,6 @@ public class GlyphData
     }
 
     /**
-     * @param boundingBoxValue The boundingBox to set.
-     */
-    public void setBoundingBox(BoundingBox boundingBoxValue)
-    {
-        this.boundingBox = boundingBoxValue;
-    }
-
-    /**
      * @return Returns the numberOfContours.
      */
     public short getNumberOfContours()
@@ -100,14 +92,6 @@ public class GlyphData
     }
 
     /**
-     * @param numberOfContoursValue The numberOfContours to set.
-     */
-    public void setNumberOfContours(short numberOfContoursValue)
-    {
-        this.numberOfContours = numberOfContoursValue;
-    }
-   
-    /**
      * Returns the description of the glyph.
      * @return the glyph description
      */

Added: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java?rev=1906970&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java (added)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java Tue Jan 24 06:37:40 2023
@@ -0,0 +1,64 @@
+/*
+ * 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.fontbox.ttf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pdfbox.io.RandomAccessRead;
+import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author Vladimir Plizga
+ */
+class GlyfCompositeDescriptTest
+{
+
+    @Test
+    @DisplayName("getComponentsView() method returns read-only list of all glyph components")
+    void getComponentsView() throws IOException
+    {
+        // given
+        OTFParser otfParser = new OTFParser();
+        String fontPath = "src/test/resources/ttf/LiberationSans-Regular.ttf";
+        OpenTypeFont font;
+        try (RandomAccessRead fontFile = new RandomAccessReadBufferedFile(fontPath))
+        {
+            font = otfParser.parse(fontFile);
+        }
+        GlyphTable glyphTable = font.getGlyph();
+        // A acute
+        GlyphData aacuteGlyph = glyphTable.getGlyph(131);
+
+        GlyphDescription glyphDescription = aacuteGlyph.getDescription();
+        // consists of glyphs 36 & 2335
+        assertTrue(glyphDescription.isComposite());
+
+        GlyfCompositeDescript compositeGlyphDescription = (GlyfCompositeDescript) glyphDescription;
+
+        // check unmodifiable list
+        List<GlyfCompositeComp> componentsView = compositeGlyphDescription.getComponents();
+        assertEquals(2, componentsView.size());
+        assertThrows(UnsupportedOperationException.class, () -> componentsView.remove(0));
+    }
+}

Propchange: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyfCompositeDescriptTest.java
------------------------------------------------------------------------------
    svn:eol-style = native