View Javadoc

1   /***********************************************************************************************************************
2    * Copyright (c) 2003, International Barcode Consortium
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without modification,
6    * are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this list of
9    * conditions and the following disclaimer.
10   * Redistributions in binary form must reproduce the above copyright notice, this list of
11   * conditions and the following disclaimer in the documentation and/or other materials
12   * provided with the distribution.
13   * Neither the name of the International Barcode Consortium nor the names of any contributors may be used to endorse
14   * or promote products derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18   * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24   * POSSIBILITY OF SUCH DAMAGE.
25   ***********************************************************************************************************************/
26  
27  package net.sourceforge.barbecue.output;
28  
29  import java.awt.*;
30  
31  
32  /**
33   * The <code>SizingOutput</code> class is used to calculate the size of a barcode.
34   * <P>
35   * This class will not generate any output.
36   * <P>
37   */
38  public class SizingOutput extends AbstractOutput {
39      private java.awt.FontMetrics fm;
40      
41      public SizingOutput(Font font, Color fgColor, Color bgColor) {
42          super(font, false, 1.0, fgColor, bgColor);
43      }
44      
45      public SizingOutput(Font font, java.awt.FontMetrics fm, Color fgColor, Color bgColor) {
46          super(font, false, 1.0, fgColor, bgColor);
47          this.fm = fm;
48      }
49      
50      /**
51       * "Draws" a bar at the given coordinates.
52       * @param x the x coordinate
53       * @param y the y coordinate
54       * @param width the width
55       * @param height the height
56       * @param paintWithForegroundColor if true, use the foreground color, otherwise use the background color
57       * @return the width of the bar drawn
58       */
59      public int drawBar(int x, int y, int width, int height, boolean paintWithForegroundColor) {
60          return (int)width;
61      }
62      
63      /**
64       * Sets up the drawing environment.  Called before drawBar().  Matched with call to
65       * endDraw() at the end.  This allows for caching as needed.
66       */
67      public void beginDraw() {
68      }
69      
70      /**
71       * Balanced with startDraw() above, used for caching, output of epilogues (for
72       * SVG), etc.
73       * @param width The output width (in pixels) of the barcode
74       * @param height The output height (in pixels) of the barcode.
75       */
76      public void endDraw(int width, int height) {
77      }
78  
79  	public int drawText(String text, LabelLayout labelLayout) throws OutputException {
80  		if(font == null || fm == null) {
81              return 0;
82          }
83  		// TODO: This is incorrect
84  		return fm.getAscent() + fm.getDescent() + fm.getLeading();
85  	}
86  
87  	/**
88       * Paint the background the background colour, based on the height and the width.
89       * @param x the x coordinate
90       * @param y the y coordinate
91       * @param width the width to be painted
92       * @param height the height to be painted
93       */
94      public void paintBackground(int x, int y, int width, int height) {
95      }
96  }