pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1792298 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox: cff/CFFParser.java cff/Type2CharString.java ttf/OTFParser.java ttf/TTFParser.java
Date Sat, 22 Apr 2017 16:31:39 GMT
Author: tilman
Date: Sat Apr 22 16:31:38 2017
New Revision: 1792298

URL: http://svn.apache.org/viewvc?rev=1792298&view=rev
Log:
PDFBOX-2852: use JDK7 syntax

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type2CharString.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1792298&r1=1792297&r2=1792298&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Sat Apr 22 16:31:38
2017
@@ -81,51 +81,44 @@ public class CFFParser
 
         String firstTag = readTagName(input);
         // try to determine which kind of font we have
-        if (TAG_OTTO.equals(firstTag))
+        switch (firstTag)
         {
-            // this is OpenType font containing CFF data
-            // so find CFF tag
-            short numTables = input.readShort();
-            @SuppressWarnings("unused")
-            short searchRange = input.readShort();
-            @SuppressWarnings("unused")
-            short entrySelector = input.readShort();
-            @SuppressWarnings("unused")
-            short rangeShift = input.readShort();
-
-            boolean cffFound = false;
-            for (int q = 0; q < numTables; q++)
-            {
-                String tagName = readTagName(input);
-                @SuppressWarnings("unused")
-                long checksum = readLong(input);
-                long offset = readLong(input);
-                long length = readLong(input);
-                if (tagName.equals("CFF "))
+            case TAG_OTTO:
+                // this is OpenType font containing CFF data
+                // so find CFF tag
+                short numTables = input.readShort();
+                @SuppressWarnings("unused") short searchRange = input.readShort();
+                @SuppressWarnings("unused") short entrySelector = input.readShort();
+                @SuppressWarnings("unused") short rangeShift = input.readShort();
+                boolean cffFound = false;
+                for (int q = 0; q < numTables; q++)
                 {
-                    cffFound = true;
-                    byte[] bytes2 = new byte[(int) length];
-                    System.arraycopy(bytes, (int) offset, bytes2, 0, bytes2.length);
-                    input = new CFFDataInput(bytes2);
-                    break;
+                    String tagName = readTagName(input);
+                    @SuppressWarnings("unused")
+                    long checksum = readLong(input);
+                    long offset = readLong(input);
+                    long length = readLong(input);
+                    if (tagName.equals("CFF "))
+                    {
+                        cffFound = true;
+                        byte[] bytes2 = new byte[(int) length];
+                        System.arraycopy(bytes, (int) offset, bytes2, 0, bytes2.length);
+                        input = new CFFDataInput(bytes2);
+                        break;
+                    }
                 }
-            }
-            if (!cffFound)
-            {
-                throw new IOException("CFF tag not found in this OpenType font.");
-            }
-        }
-        else if (TAG_TTCF.equals(firstTag))
-        {
-            throw new IOException("True Type Collection fonts are not supported.");
-        }
-        else if (TAG_TTFONLY.equals(firstTag))
-        {
-            throw new IOException("OpenType fonts containing a true type font are not supported.");
-        }
-        else
-        {
-            input.setPosition(0);
+                if (!cffFound)
+                {
+                    throw new IOException("CFF tag not found in this OpenType font.");
+                }
+                break;
+            case TAG_TTCF:
+                throw new IOException("True Type Collection fonts are not supported.");
+            case TAG_TTFONLY:
+                throw new IOException("OpenType fonts containing a true type font are not
supported.");
+            default:
+                input.setPosition(0);
+                break;
         }
 
         @SuppressWarnings("unused")

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type2CharString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type2CharString.java?rev=1792298&r1=1792297&r2=1792298&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type2CharString.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type2CharString.java Sat Apr
22 16:31:38 2017
@@ -98,160 +98,152 @@ public class Type2CharString extends Typ
         commandCount++;
         String name = CharStringCommand.TYPE2_VOCABULARY.get(command.getKey());
 
-        if ("hstem".equals(name))
+        if (name == null)
         {
-            numbers = clearStack(numbers, numbers.size() % 2 != 0);
-            expandStemHints(numbers, true);
+            return null;
         }
-        else if ("vstem".equals(name))
+        switch (name)
         {
-            numbers = clearStack(numbers, numbers.size() % 2 != 0);
-            expandStemHints(numbers, false);
-        }
-        else if ("vmoveto".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() > 1);
-            markPath();
-            addCommand(numbers, command);
-        }
-        else if ("rlineto".equals(name))
-        {
-            addCommandList(split(numbers, 2), command);
-        }
-        else if ("hlineto".equals(name))
-        {
-            drawAlternatingLine(numbers, true);
-        }
-        else if ("vlineto".equals(name))
-        {
-            drawAlternatingLine(numbers, false);
-        }
-        else if ("rrcurveto".equals(name))
-        {
-            addCommandList(split(numbers, 6), command);
-        }
-        else if ("endchar".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() == 5 || numbers.size() == 1);
-            closePath();
-            if (numbers.size() == 4)
-            {
-                // deprecated "seac" operator
-                numbers.add(0, 0);
-                addCommand(numbers, new CharStringCommand(12, 6));
-            }
-            else
-            {
+            case "hstem":
+                numbers = clearStack(numbers, numbers.size() % 2 != 0);
+                expandStemHints(numbers, true);
+                break;
+            case "vstem":
+                numbers = clearStack(numbers, numbers.size() % 2 != 0);
+                expandStemHints(numbers, false);
+                break;
+            case "vmoveto":
+                numbers = clearStack(numbers, numbers.size() > 1);
+                markPath();
                 addCommand(numbers, command);
-            }
-        }
-        else if ("rmoveto".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() > 2);
-            markPath();
-            addCommand(numbers, command);
-        }
-        else if ("hmoveto".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() > 1);
-            markPath();
-            addCommand(numbers, command);
-        }
-        else if ("vhcurveto".equals(name))
-        {
-            drawAlternatingCurve(numbers, false);
-        }
-        else if ("hvcurveto".equals(name))
-        {
-            drawAlternatingCurve(numbers, true);
-        }
-        else if ("hflex".equals(name))
-        {
-            List<Number> first = Arrays.asList(numbers.get(0), 0,
-                    numbers.get(1), numbers.get(2), numbers.get(3), 0);
-            List<Number> second = Arrays.asList(numbers.get(4), 0,
-                    numbers.get(5), -(numbers.get(2).floatValue()),
-                    numbers.get(6), 0);
-            addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
-        } 
-        else if ("flex".equals(name))
-        {
-            List<Number> first = numbers.subList(0, 6);
-            List<Number> second = numbers.subList(6, 12);
-            addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
-        }
-        else if ("hflex1".equals(name))
-        {
-            List<Number> first = Arrays.asList(numbers.get(0), numbers.get(1), 
-                    numbers.get(2), numbers.get(3), numbers.get(4), 0);
-            List<Number> second = Arrays.asList(numbers.get(5), 0,
-                    numbers.get(6), numbers.get(7), numbers.get(8), 0);
-            addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
-        }
-        else if ("flex1".equals(name))
-        {
-            int dx = 0;
-            int dy = 0;
-            for(int i = 0; i < 5; i++)
-            {
-                dx += numbers.get(i * 2).intValue();
-                dy += numbers.get(i * 2 + 1).intValue();
-            }
-            List<Number> first = numbers.subList(0, 6);
-            List<Number> second = Arrays.asList(numbers.get(6), numbers.get(7), numbers.get(8),

-                    numbers.get(9), (Math.abs(dx) > Math.abs(dy) ? numbers.get(10) : -dx),

-                    (Math.abs(dx) > Math.abs(dy) ? -dy : numbers.get(10)));
-            addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
-        }
-        else if ("hstemhm".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() % 2 != 0);
-            expandStemHints(numbers, true);
-        } 
-        else if ("hintmask".equals(name) || "cntrmask".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() % 2 != 0);
-            if (numbers.size() > 0)
-            {
+                break;
+            case "rlineto":
+                addCommandList(split(numbers, 2), command);
+                break;
+            case "hlineto":
+                drawAlternatingLine(numbers, true);
+                break;
+            case "vlineto":
+                drawAlternatingLine(numbers, false);
+                break;
+            case "rrcurveto":
+                addCommandList(split(numbers, 6), command);
+                break;
+            case "endchar":
+                numbers = clearStack(numbers, numbers.size() == 5 || numbers.size() == 1);
+                closePath();
+                if (numbers.size() == 4)
+                {
+                    // deprecated "seac" operator
+                    numbers.add(0, 0);
+                    addCommand(numbers, new CharStringCommand(12, 6));
+                }
+                else
+                {
+                    addCommand(numbers, command);
+                }
+                break;
+            case "rmoveto":
+                numbers = clearStack(numbers, numbers.size() > 2);
+                markPath();
+                addCommand(numbers, command);
+                break;
+            case "hmoveto":
+                numbers = clearStack(numbers, numbers.size() > 1);
+                markPath();
+                addCommand(numbers, command);
+                break;
+            case "vhcurveto":
+                drawAlternatingCurve(numbers, false);
+                break;
+            case "hvcurveto":
+                drawAlternatingCurve(numbers, true);
+                break;
+            case "hflex":
+            {
+                List<Number> first = Arrays.asList(numbers.get(0), 0,
+                        numbers.get(1), numbers.get(2), numbers.get(3), 0);
+                List<Number> second = Arrays.asList(numbers.get(4), 0,
+                        numbers.get(5), -(numbers.get(2).floatValue()),
+                        numbers.get(6), 0);
+                addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
+                break;
+            }
+            case "flex":
+            {
+                List<Number> first = numbers.subList(0, 6);
+                List<Number> second = numbers.subList(6, 12);
+                addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
+                break;
+            }
+            case "hflex1":
+            {
+                List<Number> first = Arrays.asList(numbers.get(0), numbers.get(1),
+                        numbers.get(2), numbers.get(3), numbers.get(4), 0);
+                List<Number> second = Arrays.asList(numbers.get(5), 0,
+                        numbers.get(6), numbers.get(7), numbers.get(8), 0);
+                addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
+                break;
+            }
+            case "flex1":
+            {
+                int dx = 0;
+                int dy = 0;
+                for (int i = 0; i < 5; i++)
+                {
+                    dx += numbers.get(i * 2).intValue();
+                    dy += numbers.get(i * 2 + 1).intValue();
+                }
+                List<Number> first = numbers.subList(0, 6);
+                List<Number> second = Arrays.asList(numbers.get(6), numbers.get(7),
numbers.get(8),
+                        numbers.get(9), (Math.abs(dx) > Math.abs(dy) ? numbers.get(10)
: -dx),
+                        (Math.abs(dx) > Math.abs(dy) ? -dy : numbers.get(10)));
+                addCommandList(Arrays.asList(first, second), new CharStringCommand(8));
+                break;
+            }
+            case "hstemhm":
+                numbers = clearStack(numbers, numbers.size() % 2 != 0);
+                expandStemHints(numbers, true);
+                break;
+            case "hintmask":
+            case "cntrmask":
+                numbers = clearStack(numbers, numbers.size() % 2 != 0);
+                if (numbers.size() > 0)
+                {
+                    expandStemHints(numbers, false);
+                }
+                break;
+            case "vstemhm":
+                numbers = clearStack(numbers, numbers.size() % 2 != 0);
                 expandStemHints(numbers, false);
-            }
-        } 
-        else if ("vstemhm".equals(name))
-        {
-            numbers = clearStack(numbers, numbers.size() % 2 != 0);
-            expandStemHints(numbers, false);
-        } 
-        else if ("rcurveline".equals(name))
-        {
-            if (numbers.size() >= 2)
-            {
-                addCommandList(split(numbers.subList(0, numbers.size() - 2), 6),
-                        new CharStringCommand(8));
-                addCommand(numbers.subList(numbers.size() - 2, numbers.size()),
-                        new CharStringCommand(5));
-            }
-        } 
-        else if ("rlinecurve".equals(name))
-        {
-            if (numbers.size() >= 6)
-            {
-                addCommandList(split(numbers.subList(0, numbers.size() - 6), 2),
-                        new CharStringCommand(5));
-                addCommand(numbers.subList(numbers.size() - 6, numbers.size()),
-                        new CharStringCommand(8));
-            }
-        } 
-        else if ("vvcurveto".equals(name))
-        {
-            drawCurve(numbers, false);
-        } 
-        else if ("hhcurveto".equals(name))
-        {
-            drawCurve(numbers, true);
-        } 
-        else
-        {
-            addCommand(numbers, command);
+                break;
+            case "rcurveline":
+                if (numbers.size() >= 2)
+                {
+                    addCommandList(split(numbers.subList(0, numbers.size() - 2), 6),
+                            new CharStringCommand(8));
+                    addCommand(numbers.subList(numbers.size() - 2, numbers.size()),
+                            new CharStringCommand(5));
+                }
+                break;
+            case "rlinecurve":
+                if (numbers.size() >= 6)
+                {
+                    addCommandList(split(numbers.subList(0, numbers.size() - 6), 2),
+                            new CharStringCommand(5));
+                    addCommand(numbers.subList(numbers.size() - 6, numbers.size()),
+                            new CharStringCommand(8));
+                }
+                break;
+            case "vvcurveto":
+                drawCurve(numbers, false);
+                break;
+            case "hhcurveto":
+                drawCurve(numbers, true);
+                break;
+            default:
+                addCommand(numbers, command);
+                break;
         }
         return null;
     }

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java?rev=1792298&r1=1792297&r2=1792298&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/OTFParser.java Sat Apr 22 16:31:38
2017
@@ -89,19 +89,18 @@ public final class OTFParser extends TTF
     protected TTFTable readTable(TrueTypeFont font, String tag)
     {
         // todo: this is a stub, a full implementation is needed
-
-        if (tag.equals("BASE") || tag.equals("GDEF") || tag.equals("GPOS") ||
-            tag.equals("GSUB") || tag.equals("JSTF"))
-        {
-            return new OTLTable(font);
-        }
-        else if (tag.equals("CFF "))
-        {
-            return new CFFTable(font);
-        }
-        else
+        switch (tag)
         {
-            return super.readTable(font, tag);
+            case "BASE":
+            case "GDEF":
+            case "GPOS":
+            case "GSUB":
+            case "JSTF":
+                return new OTLTable(font);
+            case "CFF ":
+                return new CFFTable(font);
+            default:
+                return super.readTable(font, tag);
         }
     }
 

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java?rev=1792298&r1=1792297&r2=1792298&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java Sat Apr 22 16:31:38
2017
@@ -241,69 +241,56 @@ public class TTFParser
     {
         TTFTable table = null;
         String tag = raf.readString(4);
-        if (tag.equals(CmapTable.TAG))
+        switch (tag)
         {
-            table = new CmapTable(font);
-        }
-        else if (tag.equals(GlyphTable.TAG))
-        {
-            table = new GlyphTable(font);
-        }
-        else if (tag.equals(HeaderTable.TAG))
-        {
-            table = new HeaderTable(font);
-        }
-        else if (tag.equals(HorizontalHeaderTable.TAG))
-        {
-            table = new HorizontalHeaderTable(font);
-        }
-        else if (tag.equals(HorizontalMetricsTable.TAG))
-        {
-            table = new HorizontalMetricsTable(font);
-        }
-        else if (tag.equals(IndexToLocationTable.TAG))
-        {
-            table = new IndexToLocationTable(font);
-        }
-        else if (tag.equals(MaximumProfileTable.TAG))
-        {
-            table = new MaximumProfileTable(font);
-        }
-        else if (tag.equals(NamingTable.TAG))
-        {
-            table = new NamingTable(font);
-        }
-        else if (tag.equals(OS2WindowsMetricsTable.TAG))
-        {
-            table = new OS2WindowsMetricsTable(font);
-        }
-        else if (tag.equals(PostScriptTable.TAG))
-        {
-            table = new PostScriptTable(font);
-        }
-        else if (tag.equals(DigitalSignatureTable.TAG))
-        {
-            table = new DigitalSignatureTable(font);
-        }
-        else if (tag.equals(KerningTable.TAG))
-        {
-            table = new KerningTable(font);
-        }
-        else if (tag.equals(VerticalHeaderTable.TAG))
-        {
-            table = new VerticalHeaderTable(font);
-        }
-        else if (tag.equals(VerticalMetricsTable.TAG))
-        {
-            table = new VerticalMetricsTable(font);
-        }
-        else if (tag.equals(VerticalOriginTable.TAG))
-        {
-            table = new VerticalOriginTable(font);
-        }
-        else
-        {
-            table = readTable(font, tag);
+            case CmapTable.TAG:
+                table = new CmapTable(font);
+                break;
+            case GlyphTable.TAG:
+                table = new GlyphTable(font);
+                break;
+            case HeaderTable.TAG:
+                table = new HeaderTable(font);
+                break;
+            case HorizontalHeaderTable.TAG:
+                table = new HorizontalHeaderTable(font);
+                break;
+            case HorizontalMetricsTable.TAG:
+                table = new HorizontalMetricsTable(font);
+                break;
+            case IndexToLocationTable.TAG:
+                table = new IndexToLocationTable(font);
+                break;
+            case MaximumProfileTable.TAG:
+                table = new MaximumProfileTable(font);
+                break;
+            case NamingTable.TAG:
+                table = new NamingTable(font);
+                break;
+            case OS2WindowsMetricsTable.TAG:
+                table = new OS2WindowsMetricsTable(font);
+                break;
+            case PostScriptTable.TAG:
+                table = new PostScriptTable(font);
+                break;
+            case DigitalSignatureTable.TAG:
+                table = new DigitalSignatureTable(font);
+                break;
+            case KerningTable.TAG:
+                table = new KerningTable(font);
+                break;
+            case VerticalHeaderTable.TAG:
+                table = new VerticalHeaderTable(font);
+                break;
+            case VerticalMetricsTable.TAG:
+                table = new VerticalMetricsTable(font);
+                break;
+            case VerticalOriginTable.TAG:
+                table = new VerticalOriginTable(font);
+                break;
+            default:
+                table = readTable(font, tag);
+                break;
         }
         table.setTag(tag);
         table.setCheckSum(raf.readUnsignedInt());



Mime
View raw message