📄 fontpanel.java
字号:
/// Push the actual draw area 60 down to allow info to be printed g.translate( (int) pf.getImageableX(), (int) pf.getImageableY() + 60 ); try { drawText( g, pageWidth, pageHeight - 60 ); } catch ( CannotDrawException e ) { f2dt.fireChangeStatus( ERRORS[ e.id ], true ); return NO_SUCH_PAGE; } /// Draw information about what is being printed String hints = ( " with antialias " + antiAliasType + "and" + " fractional metrics " + fractionalMetricsType + " and lcd contrast = " + lcdContrast); String infoLine1 = ( "Printing" + MS_OPENING[textToUse] + modeSpecificNumStr( drawStart ) + " to " + modeSpecificNumStr( drawEnd ) + MS_CLOSING[textToUse] ); String infoLine2 = ( "With " + fontName + " " + STYLES[fontStyle] + " at " + fontSize + " point size " + TRANSFORMS[fontTransform] ); String infoLine3 = "Using " + METHODS[drawMethod] + hints; String infoLine4 = "Page: " + ( pageIndex + 1 ); g.setFont( new Font( "dialog", Font.PLAIN, 12 )); g.setColor( Color.black ); g.translate( 0, -60 ); g.drawString( infoLine1, 15, 10 ); g.drawString( infoLine2, 15, 22 ); g.drawString( infoLine3, 15, 34 ); g.drawString( infoLine4, 15, 46 ); if ( drawEnd == drawLimit ) /// This indicates that the draw will be completed with this page lastPage = pageIndex; /// Restore the changed values back... /// This is important for JScrollBar settings and LineBreak'ed TLs drawStart = backupDrawStart; drawEnd = backupDrawEnd; numCharAcross = backupNumCharAcross; numCharDown = backupNumCharDown; if ( textToUse == FILE_TEXT ) lineBreakTLs = backupLineBreakTLs; return PAGE_EXISTS; } /// Ouputs the current canvas into a given PNG file public void writePNG( String fileName ) { try { ImageIO.write(backBuffer, "png", new java.io.File(fileName)); } catch ( Exception e ) { f2dt.fireChangeStatus( "ERROR: Failed to Save PNG image; See stack trace", true ); e.printStackTrace(); } } /// Figures out whether a character at the pointer location is valid /// And if so, updates mouse location informations, as well as /// the information on the status bar private boolean checkMouseLoc( MouseEvent e ) { if ( gridWidth != 0 && gridHeight != 0 ) if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) { int charLocX = ( e.getX() - canvasInset_X ) / gridWidth; int charLocY = ( e.getY() - canvasInset_Y ) / gridHeight; /// Check to make sure the mouse click location is within drawn area if ( charLocX >= 0 && charLocY >= 0 && charLocX < numCharAcross && charLocY < numCharDown ) { int mouseOverChar = charLocX + ( verticalBar.getValue() + charLocY ) * numCharAcross; if ( textToUse == RANGE_TEXT ) mouseOverChar += drawRange[0]; if ( mouseOverChar > drawEnd ) return false; mouseOverCharX = charLocX; mouseOverCharY = charLocY; currMouseOverChar = mouseOverChar; /// Update status bar f2dt.fireChangeStatus( "Pointing to" + MS_OPENING[textToUse] + modeSpecificNumStr( mouseOverChar ), false ); return true; } } return false; } /// Shows (updates) the character zoom window public void showZoomed() { GlyphVector gv; Font backup = testFont; Point canvasLoc = this.getLocationOnScreen(); /// Calculate the zoom area's location and size... int dialogOffsetX = (int) ( gridWidth * ( ZOOM - 1 ) / 2 ); int dialogOffsetY = (int) ( gridHeight * ( ZOOM - 1 ) / 2 ); int zoomAreaX = mouseOverCharX * gridWidth + canvasInset_X - dialogOffsetX; int zoomAreaY = mouseOverCharY * gridHeight + canvasInset_Y - dialogOffsetY; int zoomAreaWidth = (int) ( gridWidth * ZOOM ); int zoomAreaHeight = (int) ( gridHeight * ZOOM ); /// Position and set size of zoom window as needed zoomWindow.setLocation( canvasLoc.x + zoomAreaX, canvasLoc.y + zoomAreaY ); if ( !nowZooming ) { if ( zoomWindow.getWarningString() != null ) /// If this is not opened as a "secure" window, /// it has a banner below the zoom dialog which makes it look really BAD /// So enlarge it by a bit zoomWindow.setSize( zoomAreaWidth + 1, zoomAreaHeight + 20 ); else zoomWindow.setSize( zoomAreaWidth + 1, zoomAreaHeight + 1 ); } /// Prepare zoomed image zoomImage = (BufferedImage) zoomWindow.createImage( zoomAreaWidth + 1, zoomAreaHeight + 1 ); Graphics2D g2 = (Graphics2D) zoomImage.getGraphics(); testFont = testFont.deriveFont( fontSize * ZOOM ); setParams( g2 ); g2.setColor( Color.white ); g2.fillRect( 0, 0, zoomAreaWidth, zoomAreaHeight ); g2.setColor( Color.black ); g2.drawRect( 0, 0, zoomAreaWidth, zoomAreaHeight ); modeSpecificDrawChar( g2, currMouseOverChar, zoomAreaWidth / 2, (int) ( maxAscent * ZOOM )); g2.dispose(); if ( !nowZooming ) zoomWindow.show(); /// This is sort of redundant... since there is a paint function /// inside zoomWindow definition that does the drawImage. /// (I should be able to call just repaint() here) /// However, for some reason, that paint function fails to respond /// from second time and on; So I have to force the paint here... zoomWindow.getGraphics().drawImage( zoomImage, 0, 0, this ); nowZooming = true; prevZoomChar = currMouseOverChar; testFont = backup; // Windows does not repaint correctly, after // a zoom. Thus, we need to force the canvas // to repaint, but only once. After the first repaint, // everything stabilizes. [ABP] if ( firstTime() ) { refresh(); } } /// Listener Functions /// MouseListener interface function /// Zooms a character when mouse is pressed above it public void mousePressed( MouseEvent e ) { if ( !showingError) { if ( checkMouseLoc( e )) { showZoomed(); this.setCursor( blankCursor ); } } } /// MouseListener interface function /// Redraws the area that was drawn over by zoomed character public void mouseReleased( MouseEvent e ) { if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) { if ( nowZooming ) zoomWindow.hide(); nowZooming = false; } this.setCursor( Cursor.getDefaultCursor() ); } /// MouseListener interface function /// Resets the status bar to display range instead of a specific character public void mouseExited( MouseEvent e ) { if ( !showingError && !nowZooming ) f2dt.fireChangeStatus( backupStatusString, false ); } /// MouseMotionListener interface function /// Adjusts the status bar message when mouse moves over a character public void mouseMoved( MouseEvent e ) { if ( !showingError ) { if ( !checkMouseLoc( e )) f2dt.fireChangeStatus( backupStatusString, false ); } } /// MouseMotionListener interface function /// Scrolls the zoomed character when mouse is dragged public void mouseDragged( MouseEvent e ) { if ( !showingError ) if ( nowZooming ) { if ( checkMouseLoc( e ) && currMouseOverChar != prevZoomChar ) showZoomed(); } } /// Empty function to comply with interface requirement public void mouseClicked( MouseEvent e ) {} public void mouseEntered( MouseEvent e ) {} } private final class CannotDrawException extends RuntimeException { /// Error ID public final int id; public CannotDrawException( int i ) { id = i; } } enum FMValues { FMDEFAULT ("DEFAULT", VALUE_FRACTIONALMETRICS_DEFAULT), FMOFF ("OFF", VALUE_FRACTIONALMETRICS_OFF), FMON ("ON", VALUE_FRACTIONALMETRICS_ON); private String name; private Object hint; private static FMValues[] valArray; FMValues(String s, Object o) { name = s; hint = o; } public String toString() { return name; } public Object getHint() { return hint; } public static Object getValue(int ordinal) { if (valArray == null) { valArray = (FMValues[])EnumSet.allOf(FMValues.class).toArray(new FMValues[0]); } for (int i=0;i<valArray.length;i++) { if (valArray[i].ordinal() == ordinal) { return valArray[i]; } } return valArray[0]; } private static FMValues[] getArray() { if (valArray == null) { valArray = (FMValues[])EnumSet.allOf(FMValues.class).toArray(new FMValues[0]); } return valArray; } public static int getHintVal(Object hint) { getArray(); for (int i=0;i<valArray.length;i++) { if (valArray[i].getHint() == hint) { return i; } } return 0; } } enum AAValues { AADEFAULT ("DEFAULT", VALUE_TEXT_ANTIALIAS_DEFAULT), AAOFF ("OFF", VALUE_TEXT_ANTIALIAS_OFF), AAON ("ON", VALUE_TEXT_ANTIALIAS_ON), AAGASP ("GASP", VALUE_TEXT_ANTIALIAS_GASP), AALCDHRGB ("LCD_HRGB", VALUE_TEXT_ANTIALIAS_LCD_HRGB), AALCDHBGR ("LCD_HBGR", VALUE_TEXT_ANTIALIAS_LCD_HBGR), AALCDVRGB ("LCD_VRGB", VALUE_TEXT_ANTIALIAS_LCD_VRGB), AALCDVBGR ("LCD_VBGR", VALUE_TEXT_ANTIALIAS_LCD_VBGR); private String name; private Object hint; private static AAValues[] valArray; AAValues(String s, Object o) { name = s; hint = o; } public String toString() { return name; } public Object getHint() { return hint; } public static boolean isLCDMode(Object o) { return (o instanceof AAValues && ((AAValues)o).ordinal() >= AALCDHRGB.ordinal()); } public static Object getValue(int ordinal) { if (valArray == null) { valArray = (AAValues[])EnumSet.allOf(AAValues.class).toArray(new AAValues[0]); } for (int i=0;i<valArray.length;i++) { if (valArray[i].ordinal() == ordinal) { return valArray[i]; } } return valArray[0]; } private static AAValues[] getArray() { if (valArray == null) { Object [] oa = EnumSet.allOf(AAValues.class).toArray(new AAValues[0]); valArray = (AAValues[])(EnumSet.allOf(AAValues.class).toArray(new AAValues[0])); } return valArray; } public static int getHintVal(Object hint) { getArray(); for (int i=0;i<valArray.length;i++) { if (valArray[i].getHint() == hint) { return i; } } return 0; } } private static Integer defaultContrast; static Integer getDefaultLCDContrast() { if (defaultContrast == null) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); Graphics2D g2d = (Graphics2D)(gc.createCompatibleImage(1,1).getGraphics()); defaultContrast = (Integer) g2d.getRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST); } return defaultContrast; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -