< prev index next >

src/demo/share/jfc/Font2DTest/FontPanel.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * --- 1,7 ---- /* ! * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *
*** 93,130 **** /// and the custom controlled scroll bar public final class FontPanel extends JPanel implements AdjustmentListener { /// Drawing Option Constants ! private final String STYLES[] = { "plain", "bold", "italic", "bold italic" }; private final int NONE = 0; private final int SCALE = 1; private final int SHEAR = 2; private final int ROTATE = 3; ! private final String TRANSFORMS[] = { "with no transforms", "with scaling", "with Shearing", "with rotation" }; private final int DRAW_STRING = 0; private final int DRAW_CHARS = 1; private final int DRAW_BYTES = 2; private final int DRAW_GLYPHV = 3; private final int TL_DRAW = 4; private final int GV_OUTLINE = 5; private final int TL_OUTLINE = 6; ! private final String METHODS[] = { "drawString", "drawChars", "drawBytes", "drawGlyphVector", "TextLayout.draw", "GlyphVector.getOutline", "TextLayout.getOutline" }; public final int RANGE_TEXT = 0; public final int ALL_GLYPHS = 1; public final int USER_TEXT = 2; public final int FILE_TEXT = 3; ! private final String MS_OPENING[] = { " Unicode ", " Glyph Code ", " lines ", " lines " }; ! private final String MS_CLOSING[] = { "", "", " of User Text ", " of LineBreakMeasurer-reformatted Text " }; /// General Graphics Variable private final JScrollBar verticalBar; private final FontCanvas fc; --- 93,130 ---- /// and the custom controlled scroll bar public final class FontPanel extends JPanel implements AdjustmentListener { /// Drawing Option Constants ! private final String[] STYLES = { "plain", "bold", "italic", "bold italic" }; private final int NONE = 0; private final int SCALE = 1; private final int SHEAR = 2; private final int ROTATE = 3; ! private final String[] TRANSFORMS = { "with no transforms", "with scaling", "with Shearing", "with rotation" }; private final int DRAW_STRING = 0; private final int DRAW_CHARS = 1; private final int DRAW_BYTES = 2; private final int DRAW_GLYPHV = 3; private final int TL_DRAW = 4; private final int GV_OUTLINE = 5; private final int TL_OUTLINE = 6; ! private final String[] METHODS = { "drawString", "drawChars", "drawBytes", "drawGlyphVector", "TextLayout.draw", "GlyphVector.getOutline", "TextLayout.getOutline" }; public final int RANGE_TEXT = 0; public final int ALL_GLYPHS = 1; public final int USER_TEXT = 2; public final int FILE_TEXT = 3; ! private final String[] MS_OPENING = { " Unicode ", " Glyph Code ", " lines ", " lines " }; ! private final String[] MS_CLOSING = { "", "", " of User Text ", " of LineBreakMeasurer-reformatted Text " }; /// General Graphics Variable private final JScrollBar verticalBar; private final FontCanvas fc;
*** 151,164 **** private Object antiAliasType = VALUE_TEXT_ANTIALIAS_DEFAULT; private Object fractionalMetricsType = VALUE_FRACTIONALMETRICS_DEFAULT; private Object lcdContrast = getDefaultLCDContrast(); private int drawMethod = DRAW_STRING; private int textToUse = RANGE_TEXT; ! private String userText[] = null; ! private String fileText[] = null; ! private int drawRange[] = { 0x0000, 0x007f }; ! private String fontInfos[] = new String[2]; private boolean showGrid = true; /// Parent Font2DTest panel private final Font2DTest f2dt; private final JFrame parent; --- 151,164 ---- private Object antiAliasType = VALUE_TEXT_ANTIALIAS_DEFAULT; private Object fractionalMetricsType = VALUE_FRACTIONALMETRICS_DEFAULT; private Object lcdContrast = getDefaultLCDContrast(); private int drawMethod = DRAW_STRING; private int textToUse = RANGE_TEXT; ! private String[] userText = null; ! private String[] fileText = null; ! private int[] drawRange = { 0x0000, 0x007f }; ! private String[] fontInfos = new String[2]; private boolean showGrid = true; /// Parent Font2DTest panel private final Font2DTest f2dt; private final JFrame parent;
*** 269,280 **** public void setDrawMethod( int i ) { drawMethod = i; fc.repaint(); } ! public void setTextToDraw( int i, int range[], ! String textSet[], String fileData[] ) { textToUse = i; if ( textToUse == RANGE_TEXT ) drawRange = range; else if ( textToUse == ALL_GLYPHS ) --- 269,280 ---- public void setDrawMethod( int i ) { drawMethod = i; fc.repaint(); } ! public void setTextToDraw( int i, int[] range, ! String[] textSet, String[] fileData ) { textToUse = i; if ( textToUse == RANGE_TEXT ) drawRange = range; else if ( textToUse == ALL_GLYPHS )
*** 375,386 **** /// Reload all options and refreshes the canvas public void loadOptions( boolean grid, boolean force16, int start, int end, String name, float size, int style, int transform, int g2transform, int text, int method, int aa, int fm, ! int contrast, String user[] ) { ! int range[] = { start, end }; /// Since repaint call has a low priority, these functions will finish /// before the actual repainting is done setGridDisplay( grid ); setForce16Columns( force16 ); --- 375,386 ---- /// Reload all options and refreshes the canvas public void loadOptions( boolean grid, boolean force16, int start, int end, String name, float size, int style, int transform, int g2transform, int text, int method, int aa, int fm, ! int contrast, String[] user ) { ! int[] range = { start, end }; /// Since repaint call has a low priority, these functions will finish /// before the actual repainting is done setGridDisplay( grid ); setForce16Columns( force16 );
*** 456,466 **** /// Status bar message backup private String backupStatusString = null; /// Error constants ! private final String ERRORS[] = { "ERROR: drawBytes cannot handle characters beyond 0x00FF. Select different range or draw methods.", "ERROR: Cannot fit text with the current font size. Resize the window or use smaller font size.", "ERROR: Cannot print with the current font size. Use smaller font size.", }; --- 456,466 ---- /// Status bar message backup private String backupStatusString = null; /// Error constants ! private final String[] ERRORS = { "ERROR: drawBytes cannot handle characters beyond 0x00FF. Select different range or draw methods.", "ERROR: Cannot fit text with the current font size. Resize the window or use smaller font size.", "ERROR: Cannot print with the current font size. Use smaller font size.", };
*** 478,488 **** this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); ! byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { --- 478,488 ---- this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); ! byte[] bogus = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) {
*** 543,554 **** /// Draws one character at time onto the canvas according to /// the method requested (Used for RANGE_TEXT and ALL_GLYPHS) public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; ! int oneGlyph[] = { charCode }; ! char charArray[] = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance --- 543,554 ---- /// Draws one character at time onto the canvas according to /// the method requested (Used for RANGE_TEXT and ALL_GLYPHS) public void modeSpecificDrawChar( Graphics2D g2, int charCode, int baseX, int baseY ) { GlyphVector gv; ! int[] oneGlyph = { charCode }; ! char[] charArray = Character.toChars( charCode ); FontRenderContext frc = g2.getFontRenderContext(); AffineTransform oldTX = g2.getTransform(); /// Create GlyphVector to measure the exact visual advance
*** 561,571 **** int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { ! double pt[] = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2); --- 561,571 ---- int shiftedX = baseX; // getPixelBounds returns a result in device space. // we need to convert back to user space to be able to // calculate the shift as baseX is in user space. try { ! double[] pt = new double[4]; pt[0] = r2d2.getX(); pt[1] = r2d2.getY(); pt[2] = r2d2.getX()+r2d2.getWidth(); pt[3] = r2d2.getY()+r2d2.getHeight(); oldTX.inverseTransform(pt,0,pt,0,2);
*** 595,605 **** g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); ! byte oneByte[] = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break; --- 595,605 ---- g2.drawChars( charArray, 0, 1, 0, 0 ); break; case DRAW_BYTES: if ( charCode > 0xff ) throw new CannotDrawException( DRAW_BYTES_ERROR ); ! byte[] oneByte = { (byte) charCode }; g2.drawBytes( oneByte, 0, 1, 0, 0 ); break; case DRAW_GLYPHV: g2.drawGlyphVector( gv, 0f, 0f ); break;
*** 642,652 **** case DRAW_CHARS: g2.drawChars( line.toCharArray(), 0, line.length(), 0, 0 ); break; case DRAW_BYTES: try { ! byte lineBytes[] = line.getBytes( "ISO-8859-1" ); g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 ); } catch ( Exception e ) { e.printStackTrace(); } --- 642,652 ---- case DRAW_CHARS: g2.drawChars( line.toCharArray(), 0, line.length(), 0, 0 ); break; case DRAW_BYTES: try { ! byte[] lineBytes = line.getBytes( "ISO-8859-1" ); g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 ); } catch ( Exception e ) { e.printStackTrace(); }
*** 932,942 **** TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i ); xPos = oneLine.isLeftToRight() ? canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X ); ! float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()}; if (g2Transform != NONE) { AffineTransform at = getAffineTransform(g2Transform); at.transform( fmData, 0, fmData, 0, 3); } //yPos += oneLine.getAscent(); --- 932,942 ---- TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i ); xPos = oneLine.isLeftToRight() ? canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X ); ! float[] fmData = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()}; if (g2Transform != NONE) { AffineTransform at = getAffineTransform(g2Transform); at.transform( fmData, 0, fmData, 0, 3); } //yPos += oneLine.getAscent();
< prev index next >