OSDN Git Service

91f1421e50587c07ff660b04e62212ae3926c323
[dvibrowser/dvi2epub.git] / src / jp / sourceforge / dvibrowser / dvicore / render / VirtualFontGeometer.java
1 /*
2  * Copyright (c) 2009, Takeyuki Nagao
3  * All rights reserved.
4  * 
5  * Redistribution and use in source and binary forms, with or
6  * without modification, are permitted provided that the
7  * following conditions are met:
8  * 
9  *  * Redistributions of source code must retain the above
10  *    copyright notice, this list of conditions and the
11  *    following disclaimer.
12  *  * Redistributions in binary form must reproduce the above
13  *    copyright notice, this list of conditions and the
14  *    following disclaimer in the documentation and/or other
15  *    materials provided with the distribution.
16  *    
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
29  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  */
32
33 package jp.sourceforge.dvibrowser.dvicore.render;
34
35 import jp.sourceforge.dvibrowser.dvicore.DviException;
36 import jp.sourceforge.dvibrowser.dvicore.DviFontSpec;
37 import jp.sourceforge.dvibrowser.dvicore.api.DviContextSupport;
38
39 public class VirtualFontGeometer 
40 extends BasicGeometer
41 {
42   private final DviFontSpec fs;
43   private final double factor;
44   public VirtualFontGeometer(DviContextSupport dcs, DviFontSpec fs) {
45     super(dcs);
46     this.fs = fs;
47     factor = (double) fs.spaceSize() / (double)(1 << 20);
48   }
49   
50   public DviFontSpec getFontSpec() {
51           return fs;
52   }
53
54   private int scale(int a) {
55     return (int)(a * factor);
56   }
57
58   public void doSetRule(int width, int height) throws DviException {
59     super.doSetRule(
60       scale(width), scale(height)
61     );
62   }
63
64   public void doPutRule(int width, int height) throws DviException {
65     super.doPutRule(
66       scale(width), scale(height)
67     );
68   }
69
70   public void doRight(int by) throws DviException {
71     super.doRight(scale(by));
72   }
73   public void doW(int by) throws DviException {
74     super.doW(scale(by));
75   }
76   public void doX(int by) throws DviException {
77     super.doX(scale(by));
78   }
79
80   public void doDown(int by) throws DviException {
81     super.doDown(scale(by));
82   }
83   public void doY(int by) throws DviException {
84     super.doY(scale(by));
85   }
86   public void doZ(int by) throws DviException {
87     super.doZ(scale(by));
88   }
89 }