Java Code Examples for java.awt.font.GlyphVector#getOutline()
The following examples show how to use
java.awt.font.GlyphVector#getOutline() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwtStrokeExample.java From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 | 6 votes |
@Override public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Get a shape to work with. Here we'll use the letter B Font f = new Font("全字庫正宋體", Font.BOLD, 140); GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "一永應木"); System.out.println(gv.getNumGlyphs()); Shape shape = gv.getOutline(); // Set drawing attributes and starting position g.setColor(Color.black); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(20, 160); // Draw the shape once with each stroke for (int i = 0; i < strokes.length; i++) { g.setStroke(strokes[i]); // set the stroke g.draw(shape); // draw the shape g.translate(0, 160); // move to the right } }
Example 2
Source File: FontRefSettingTool.java From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 | 6 votes |
/** * 依照字型號碼,設定新的活字物件。 * * @param 字型號碼 * 愛設定的字型號碼資料 * @return 依照字型號碼的活字物件 */ private SeprateMovabletype 查物件活字(CommonFontNo 字型號碼) { SeprateMovabletype 物件活字 = null; if (字體.有這个字型無(字型號碼)) { GlyphVector glyphVector = 字體.提這个字型(字體渲染屬性, 字型號碼); 物件活字 = new SeprateMovabletype(new PlaneGeometry(glyphVector.getOutline())); 物件活字.設字範圍(tzuModelTerritory); 物件活字.設目標範圍(物件活字.這馬字範圍()); } else { 物件活字 = findWenForNoBuiltIn(null); } 物件活字.徙轉原點();// TODO 伊佮這个資訊攏提掉,交予排版系統去處理,但是會有一字問題。 return 物件活字; }
Example 3
Source File: AwtStrokeProblemExample.java From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 | 6 votes |
@Override public void paint(Graphics g1) { Graphics2D graphics2D = (Graphics2D) g1; Font f = new Font("全字庫正宋體", Font.BOLD, 700); GlyphVector gv = f.createGlyphVector(graphics2D.getFontRenderContext(), "永森應言木變"); System.out.println(gv.getNumGlyphs()); Area area = new Area(gv.getOutline()); graphics2D.setColor(Color.black); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.translate(20, 700); for (int i = 10; i >= 0; i -= 2) { Color color=new Color((10-i)*0x151515); graphics2D.setColor(color); graphics2D.setStroke(new BasicStroke(i*10)); graphics2D.draw(area); graphics2D.setStroke(new NullStroke()); graphics2D.draw(area); // graphics2D.translate(10, 0); } }
Example 4
Source File: TextMeasureTests.java From hottub with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { s = gv.getOutline(); } while (--numReps >= 0); }
Example 5
Source File: OutlineTextRenderer.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 6
Source File: OutlineTextRenderer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 7
Source File: OutlineTextRenderer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 8
Source File: SimpleFeaturePointFigure.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void drawLabel(Rendering rendering, String label) { final Graphics2D graphics = rendering.getGraphics(); final Font oldFont = graphics.getFont(); final Stroke oldStroke = graphics.getStroke(); final Paint oldPaint = graphics.getPaint(); try { graphics.setFont(labelFont); GlyphVector glyphVector = labelFont.createGlyphVector(graphics.getFontRenderContext(), label); Rectangle2D logicalBounds = glyphVector.getLogicalBounds(); float tx = (float) (logicalBounds.getX() - 0.5 * logicalBounds.getWidth()); float ty = (float) (getSymbol().getBounds().getMaxY() + logicalBounds.getHeight() + 1.0); Shape labelOutline = glyphVector.getOutline(tx, ty); for (int i = 0; i < labelOutlineAlphas.length; i++) { graphics.setStroke(labelOutlineStrokes[i]); graphics.setPaint(labelOutlineColors[i]); graphics.draw(labelOutline); } graphics.setPaint(labelFontColor); graphics.fill(labelOutline); } finally { graphics.setPaint(oldPaint); graphics.setStroke(oldStroke); graphics.setFont(oldFont); } }
Example 9
Source File: TextMeasureTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { s = gv.getOutline(); } while (--numReps >= 0); }
Example 10
Source File: OutlineTextRenderer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 11
Source File: OutlineTextRenderer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 12
Source File: TextMeasureTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { s = gv.getOutline(); } while (--numReps >= 0); }
Example 13
Source File: OutlineTextRenderer.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 14
Source File: TextMeasureTests.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { s = gv.getOutline(); } while (--numReps >= 0); }
Example 15
Source File: OutlineTextRenderer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 16
Source File: OutlineTextRenderer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void drawGlyphVector(SunGraphics2D g2d, GlyphVector gv, float x, float y) { Shape s = gv.getOutline(x, y); int prevaaHint = - 1; FontRenderContext frc = gv.getFontRenderContext(); boolean aa = frc.isAntiAliased(); /* aa will be true if any AA mode has been specified. * ie for LCD and 'gasp' modes too. * We will check if 'gasp' has resolved AA to be "OFF", and * in all other cases (ie AA ON and all LCD modes) use AA outlines. */ if (aa) { if (g2d.getGVFontInfo(gv.getFont(), frc).aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF) { aa = false; } } if (aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON; g2d.validatePipe(); } else if (!aa && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) { prevaaHint = g2d.antialiasHint; g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; g2d.validatePipe(); } g2d.fill(s); if (prevaaHint != -1) { g2d.antialiasHint = prevaaHint; g2d.validatePipe(); } }
Example 17
Source File: EpsGraphics2D.java From osp with GNU General Public License v3.0 | 4 votes |
/** * Draws a GlyphVector at (x,y) */ public void drawGlyphVector(GlyphVector g, float x, float y) { Shape shape = g.getOutline(x, y); draw(shape, "fill"); //$NON-NLS-1$ }
Example 18
Source File: PFont.java From CPE552-Java with GNU General Public License v3.0 | 4 votes |
public PShape getShape(char ch, float detail) { Font font = (Font) getNative(); if (font == null) { throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()"); } PShape s = new PShape(PShape.PATH); // six element array received from the Java2D path iterator float[] iterPoints = new float[6]; // array passed to createGylphVector char[] textArray = new char[] { ch }; //Graphics2D graphics = (Graphics2D) this.getGraphics(); //FontRenderContext frc = graphics.getFontRenderContext(); @SuppressWarnings("deprecation") FontRenderContext frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, textArray); Shape shp = gv.getOutline(); // make everything into moveto and lineto PathIterator iter = (detail == 0) ? shp.getPathIterator(null) : // maintain curves shp.getPathIterator(null, detail); // convert to line segments int contours = 0; //boolean outer = true; // boolean contour = false; while (!iter.isDone()) { int type = iter.currentSegment(iterPoints); switch (type) { case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints // System.out.println("moveto"); // if (!contour) { if (contours == 0) { s.beginShape(); } else { s.beginContour(); // contour = true; } contours++; s.vertex(iterPoints[0], iterPoints[1]); break; case PathIterator.SEG_LINETO: // 1 point // System.out.println("lineto"); // PApplet.println(PApplet.subset(iterPoints, 0, 2)); s.vertex(iterPoints[0], iterPoints[1]); break; case PathIterator.SEG_QUADTO: // 2 points // System.out.println("quadto"); // PApplet.println(PApplet.subset(iterPoints, 0, 4)); s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3]); break; case PathIterator.SEG_CUBICTO: // 3 points // System.out.println("cubicto"); // PApplet.println(iterPoints); s.quadraticVertex(iterPoints[0], iterPoints[1], iterPoints[2], iterPoints[3], iterPoints[4], iterPoints[5]); break; case PathIterator.SEG_CLOSE: // System.out.println("close"); if (contours > 1) { // contours--; // if (contours == 0) { //// s.endShape(); // } else { s.endContour(); } break; } // PApplet.println(iterPoints); iter.next(); } s.endShape(CLOSE); return s; }
Example 19
Source File: TextClipErrorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Locale.setDefault(Locale.US); // initialize j.u.l Looger: final Logger log = Logger.getLogger("sun.java2d.marlin"); log.addHandler(new Handler() { @Override public void publish(LogRecord record) { Throwable th = record.getThrown(); // detect any Throwable: if (th != null) { System.out.println("Test failed:\n" + record.getMessage()); th.printStackTrace(System.out); throw new RuntimeException("Test failed: ", th); } } @Override public void flush() { } @Override public void close() throws SecurityException { } }); log.info("TextClipErrorTest: start"); // enable Marlin logging & internal checks: System.setProperty("sun.java2d.renderer.log", "true"); System.setProperty("sun.java2d.renderer.useLogger", "true"); System.setProperty("sun.java2d.renderer.doChecks", "true"); BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setColor(Color.red); try { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = g2d.getFont(); FontRenderContext frc = new FontRenderContext( new AffineTransform(), true, true); g2d.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); final Shape badShape; if (SERIALIZE) { final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6"); final Shape textShape = gv1.getOutline(); final AffineTransform at1 = AffineTransform.getTranslateInstance( -2091202.554154681, 5548.601436981691); badShape = at1.createTransformedShape(textShape); serializeShape(badShape); } else { badShape = deserializeShape(); } g2d.draw(badShape); // Draw anything within bounds and it fails: g2d.draw(new Line2D.Double(10, 20, 30, 40)); if (SAVE_IMAGE) { final File file = new File("TextClipErrorTest.png"); System.out.println("Writing file: " + file.getAbsolutePath()); ImageIO.write(image, "PNG", file); } } catch (IOException ex) { ex.printStackTrace(); } finally { g2d.dispose(); log.info("TextClipErrorTest: end"); } }
Example 20
Source File: SLGraphics.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Renders the text of the specified * {@link GlyphVector} using * the <code>Graphics2D</code> context's rendering attributes. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code>, <code>Paint</code>, and * <code>Composite</code> attributes. The <code>GlyphVector</code> * specifies individual glyphs from a {@link Font}. * The <code>GlyphVector</code> can also contain the glyph positions. * This is the fastest way to render a set of characters to the * screen. * * @param g the <code>GlyphVector</code> to be rendered * @param x the x position in user space where the glyphs should be * rendered * @param y the y position in user space where the glyphs should be * rendered * * @see java.awt.Font#createGlyphVector(FontRenderContext, char[]) * @see java.awt.font.GlyphVector * @see #setPaint * @see java.awt.Graphics#setColor * @see #setTransform * @see #setComposite * @see #setClip(Shape) */ public void drawGlyphVector(GlyphVector g, float x, float y) { Shape glyphOutline = g.getOutline(x, y); fill(glyphOutline); }