Skip to content

Commit

Permalink
PDFBOX-2941: clean up the font encoding panel
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1755755 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jahewson committed Aug 10, 2016
1 parent 6f0e70d commit a8fb957
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

package org.apache.pdfbox.debugger.fontencodingpane;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
Expand All @@ -30,13 +38,6 @@
import java.awt.image.BufferedImage;
import java.util.Iterator;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.TableCellRenderer;

/**
* @author Khyrul Bashar
Expand Down Expand Up @@ -98,6 +99,7 @@ private JTable getTable(Object[][] tableData, String[] columnNames, double[] yBo
private JPanel getHeaderPanel(Map<String, String> attributes)
{
JPanel headerPanel = new JPanel(new GridBagLayout());
headerPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 5, 0));

if (attributes != null)
{
Expand All @@ -107,7 +109,8 @@ private JPanel getHeaderPanel(Map<String, String> attributes)
{
String key = keys.next();
JLabel encodingNameLabel = new JLabel(key + ": " + attributes.get(key));
encodingNameLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 17));
encodingNameLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 16));
encodingNameLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));

GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
Expand Down Expand Up @@ -145,22 +148,22 @@ public Component getTableCellRendererComponent(JTable jTable, Object o, boolean
if (bounds2D.isEmpty())
{
JLabel label = new JLabel(SimpleFont.NO_GLYPH, SwingConstants.CENTER);
label.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 25));
label.setForeground(Color.RED);
label.setFont(new Font(Font.DIALOG, Font.PLAIN, 16));
label.setForeground(Color.GRAY);
return label;
}
Rectangle cellRect = jTable.getCellRect(row, col, false);
BufferedImage bim = renderGlyph(path, bounds2D, cellRect);
return new JLabel(new ImageIcon(bim));
return new JLabel(new ImageIcon(bim), SwingConstants.CENTER);
}
if (o != null)
{
JLabel label = new JLabel(o.toString(), SwingConstants.CENTER);
label.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 25));
label.setFont(new Font(Font.DIALOG, Font.PLAIN, 16));
if (SimpleFont.NO_GLYPH.equals(o) || ".notdef".equals(o))
{
label.setText(o.toString());
label.setForeground(Color.RED);
label.setForeground(Color.GRAY);
}
return label;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package org.apache.pdfbox.debugger.fontencodingpane;

import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
import org.apache.pdfbox.pdmodel.font.PDVectorFont;

import javax.swing.JPanel;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.JPanel;
import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
import org.apache.pdfbox.pdmodel.font.PDVectorFont;

/**
* @author Khyrul Bashar
* A class that shows the glyph table along with unicode characters for SimpleFont.
*/
class SimpleFont extends FontPane
{
public static final String NO_GLYPH = "No glyph";
private int totalAvailableGlyph = 0;
public static final String NO_GLYPH = "None";
private final FontEncodingView view;
private int totalAvailableGlyph = 0;

/**
* Constructor.
Expand All @@ -45,9 +46,9 @@ class SimpleFont extends FontPane
double[] yBounds = getYBounds(tableData, 3);

Map<String, String> attributes = new LinkedHashMap<String, String>();
attributes.put("Encoding", getEncodingName(font));
attributes.put("Font", font.getName());
attributes.put("Glyph count", Integer.toString(totalAvailableGlyph));
attributes.put("Encoding", getEncodingName(font));
attributes.put("Glyphs", Integer.toString(totalAvailableGlyph));

view = new FontEncodingView(tableData, attributes,
new String[] {"Code", "Glyph Name", "Unicode Character", "Glyph"}, yBounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package org.apache.pdfbox.debugger.fontencodingpane;

import java.awt.Dimension;
import java.awt.geom.GeneralPath;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.JPanel;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
Expand All @@ -32,15 +25,23 @@
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;

import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.geom.GeneralPath;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* @author Khyrul Bashar
* A class that shows the CIDToGID table along with unicode characters for Type0Fonts when descendent
* font is of type PDCIDFontType2.
*/
class Type0Font extends FontPane
{
private final FontEncodingView view;
public static final String NO_GLYPH = "No glyph";
private final FontEncodingView view;
private int totalAvailableGlyph = 0;

/**
Expand All @@ -56,7 +57,7 @@ class Type0Font extends FontPane
{
Map<String, String> attributes = new LinkedHashMap<String, String>();
attributes.put("Font", descendantFont.getName());
attributes.put("CID count", Integer.toString(cidtogid.length));
attributes.put("CIDs", Integer.toString(cidtogid.length));

view = new FontEncodingView(cidtogid, attributes,
new String[]{"CID", "GID", "Unicode Character", "Glyph"}, getYBounds(cidtogid, 3));
Expand All @@ -66,8 +67,8 @@ class Type0Font extends FontPane
Object[][] tab = readMap(descendantFont, parentFont);
Map<String, String> attributes = new LinkedHashMap<String, String>();
attributes.put("Font", descendantFont.getName());
attributes.put("CID count", Integer.toString(tab.length));
attributes.put("Glyph count", Integer.toString(totalAvailableGlyph));
attributes.put("CIDs", Integer.toString(tab.length));
attributes.put("Glyphs", Integer.toString(totalAvailableGlyph));

view = new FontEncodingView(tab, attributes,
new String[]{"Code", "CID", "GID", "Unicode Character", "Glyph"}, getYBounds(tab, 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

package org.apache.pdfbox.debugger.fontencodingpane;

import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
import org.apache.pdfbox.pdmodel.font.PDType3Font;

import javax.swing.JPanel;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.JPanel;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
import org.apache.pdfbox.pdmodel.font.PDType3CharProc;
import org.apache.pdfbox.pdmodel.font.PDType3Font;

/**
* @author Khyrul Bashar
Expand All @@ -32,8 +31,8 @@
class Type3Font extends FontPane
{
public static final String NO_GLYPH = "No glyph";
private int totalAvailableGlyph = 0;
private final FontEncodingView view;
private int totalAvailableGlyph = 0;

/**
* Constructor.
Expand All @@ -45,9 +44,9 @@ class Type3Font extends FontPane
Object[][] tableData = getGlyphs(font);

Map<String, String> attributes = new LinkedHashMap<String, String>();
attributes.put("Encoding", getEncodingName(font));
attributes.put("Font", font.getName());
attributes.put("Glyph count", Integer.toString(totalAvailableGlyph));
attributes.put("Encoding", getEncodingName(font));
attributes.put("Glyphs", Integer.toString(totalAvailableGlyph));

view = new FontEncodingView(tableData, attributes, new String[] {"Code", "Glyph Name", "Unicode Character"}, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@

package org.apache.pdfbox.debugger.pagepane;

import java.awt.Color;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.debugger.ui.ImageUtil;
import org.apache.pdfbox.debugger.ui.RotationMenu;
import org.apache.pdfbox.debugger.ui.ZoomMenu;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.rendering.PDFRenderer;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
Expand All @@ -27,20 +42,7 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.debugger.ui.ImageUtil;
import org.apache.pdfbox.debugger.ui.RotationMenu;
import org.apache.pdfbox.debugger.ui.ZoomMenu;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.rendering.PDFRenderer;
import java.util.concurrent.TimeUnit;

/**
* Display the page number and a page rendering.
Expand All @@ -50,14 +52,14 @@
*/
public class PagePane implements ActionListener, AncestorListener, MouseMotionListener, MouseListener
{
private final PDDocument document;
private final JLabel statuslabel;
private final PDPage page;
private JPanel panel;
private int pageIndex = -1;
private final PDDocument document;
private JLabel label;
private ZoomMenu zoomMenu;
private RotationMenu rotationMenu;
private final JLabel statuslabel;
private final PDPage page;

public PagePane(PDDocument document, COSDictionary pageDict, JLabel statuslabel)
{
Expand All @@ -77,14 +79,13 @@ private void initUI()

JLabel pageLabel = new JLabel(pageLabelText);
pageLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
pageLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 30));
pageLabel.setBackground(Color.GREEN);
pageLabel.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
pageLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
panel.add(pageLabel);

label = new JLabel();
label.addMouseMotionListener(this);
label.addMouseListener(this);
label.setBackground(panel.getBackground());
label.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(label);
panel.addAncestorListener(this);
Expand Down Expand Up @@ -230,12 +231,16 @@ protected BufferedImage doInBackground() throws IOException
{
label.setIcon(null);
label.setText("Rendering...");
PDFRenderer renderer = new PDFRenderer(document);
long t0 = System.currentTimeMillis();
statuslabel.setText("Rendering...");

PDFRenderer renderer = new PDFRenderer(document);

long t0 = System.nanoTime();
BufferedImage bim = renderer.renderImage(pageIndex, scale);
float t = (System.currentTimeMillis() - t0) / 1000f;
statuslabel.setText("Rendered in " + t + " second" + (t > 1 ? "s" : ""));
long t1 = System.nanoTime();

long ms = TimeUnit.MILLISECONDS.convert(t1 - t0, TimeUnit.NANOSECONDS);
statuslabel.setText("Rendered in " + ms + " ms");
return ImageUtil.getRotatedImage(bim, rotation);
}

Expand Down

0 comments on commit a8fb957

Please sign in to comment.