01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id$ */
19:
20: package org.apache.xmlgraphics.java2d.ps;
21:
22: import java.awt.Shape;
23: import java.awt.font.FontRenderContext;
24: import java.awt.font.GlyphVector;
25: import java.io.IOException;
26:
27: /**
28: * Default TextHandler implementation which paints text using graphics primitives (shapes).
29: */
30: public class StrokingTextHandler implements TextHandler {
31:
32: private PSGraphics2D g2d;
33:
34: public StrokingTextHandler(PSGraphics2D g2d) {
35: this .g2d = g2d;
36: }
37:
38: /** @see org.apache.xmlgraphics.java2d.ps.TextHandler#writeSetup() */
39: public void writeSetup() throws IOException {
40: //nop
41: }
42:
43: /** @see org.apache.xmlgraphics.java2d.ps.TextHandler#writePageSetup() */
44: public void writePageSetup() throws IOException {
45: //nop
46: }
47:
48: /** @see TextHandler#drawString(java.lang.String, float, float) */
49: public void drawString(String text, float x, float y) {
50: java.awt.Font awtFont = g2d.getFont();
51: FontRenderContext frc = g2d.getFontRenderContext();
52: GlyphVector gv = awtFont.createGlyphVector(frc, text);
53: Shape glyphOutline = gv.getOutline(x, y);
54: g2d.fill(glyphOutline);
55: }
56:
57: }
|