[wadalabfont-kit] / java / Renderer.java  

Annotation of /java/Renderer.java

Parent Directory | Revision Log

Revision: 1.2 - (view) (download) (as text)

1 : ktanaka 1.1 //
2 :     // Skeleton$B%G!<%?$rEO$7$F(B, $B%"%&%H%i%$%s$rJV$9(B
3 :     //
4 :     public class Renderer {
5 :     static final boolean debug=false;
6 :     static Point[] indexToPoints(Point[] points,int[] indices){
7 :     int i,len=indices.length;
8 :     Point[] ret=new Point[len];
9 :     for(i=0;i<len;i++)
10 :     ret[i]=points[indices[i]];
11 :     return ret;
12 :     }
13 :     public Outline[] elementRenderer(Point[] points,Element element){
14 :     int type=element.type;
15 :     Point[] elementPoints=indexToPoints(points,element.points);
16 :     switch(type){
17 :     case Element.ten:
18 :     return ten(elementPoints,element.annotations);
19 :     case Element.tate:
20 :     return tate(elementPoints,element.annotations);
21 :     case Element.yoko:
22 :     return yoko(elementPoints,element.annotations);
23 :     case Element.migiue:
24 :     return migiue(elementPoints,element.annotations);
25 :     case Element.hidari:
26 :     return hidari(elementPoints,element.annotations);
27 :     case Element.tatehidari:
28 :     return tatehidari(elementPoints,element.annotations);
29 :     case Element.migi:
30 :     return migi(elementPoints,element.annotations);
31 :     case Element.kozato:
32 :     return kozato(elementPoints,element.annotations);
33 :     case Element.tatehane:
34 :     return tatehane(elementPoints,element.annotations);
35 :     case Element.tsukurihane:
36 :     return tsukurihane(elementPoints,element.annotations);
37 :     case Element.sanzui:
38 :     return sanzui(elementPoints,element.annotations);
39 :     case Element.kokoro:
40 :     return kokoro(elementPoints,element.annotations);
41 :     case Element.tasuki:
42 :     return tasuki(elementPoints,element.annotations);
43 :     case Element.magaritate:
44 :     return magaritate(elementPoints,element.annotations);
45 :     case Element.kagi:
46 :     return kagi(elementPoints,element.annotations);
47 :     case Element.shin_nyuu:
48 :     return shin_nyuu(elementPoints,element.annotations);
49 :     case Element.hira_long:
50 :     return hira_long(elementPoints,element.annotations);
51 :     case Element.hira_circle:
52 :     return hira_circle(elementPoints,element.annotations);
53 :     case Element.outline:
54 :     return outline(elementPoints,element.annotations);
55 :     }
56 :     return null;
57 :     }
58 :     public Outline[] ten(Point[] points,ElementAnnotation[] annotations){
59 :     return null;
60 :     }
61 :     public Outline[] tate(Point[] points,ElementAnnotation[] annotations){
62 :     return null;
63 :     }
64 :     public Outline[] yoko(Point[] points,ElementAnnotation[] annotations){
65 :     return null;
66 :     }
67 :     public Outline[] migiue(Point[] points,ElementAnnotation[] annotations){
68 :     return null;
69 :     }
70 :     public Outline[] hidari(Point[] points,ElementAnnotation[] annotations){
71 :     return null;
72 :     }
73 :     public Outline[] tatehidari(Point[] points,ElementAnnotation[] annotations){
74 :     return null;
75 :     }
76 :     public Outline[] migi(Point[] points,ElementAnnotation[] annotations){
77 :     return null;
78 :     }
79 :     public Outline[] kozato(Point[] points,ElementAnnotation[] annotations){
80 :     return null;
81 :     }
82 :     public Outline[] tatehane(Point[] points,ElementAnnotation[] annotations){
83 :     return null;
84 :     }
85 :     public Outline[] tsukurihane(Point[] points,ElementAnnotation[] annotations){
86 :     return null;
87 :     }
88 :     public Outline[] sanzui(Point[] points,ElementAnnotation[] annotations){
89 :     return null;
90 :     }
91 :     public Outline[] kokoro(Point[] points,ElementAnnotation[] annotations){
92 :     return null;
93 :     }
94 :     public Outline[] tasuki(Point[] points,ElementAnnotation[] annotations){
95 :     return null;
96 :     }
97 :     public Outline[] magaritate(Point[] points,ElementAnnotation[] annotations){
98 :     return null;
99 :     }
100 :     public Outline[] kagi(Point[] points,ElementAnnotation[] annotations){
101 :     return null;
102 :     }
103 :     public Outline[] shin_nyuu(Point[] points,ElementAnnotation[] annotations){
104 :     return null;
105 :     }
106 :     public Outline[] hira_long(Point[] points,ElementAnnotation[] annotations){
107 :     return null;
108 :     }
109 :     public Outline[] hira_circle(Point[] points,ElementAnnotation[] annotations){
110 :     return null;
111 :     }
112 :     public Outline[] outline(Point[] points,ElementAnnotation[] annotations){
113 :     return null;
114 :     }
115 :     // p0 $B$H(B p1 $B$N4V$rI}(B width $B$GD>@~FyIU$1(B
116 :     public Outline[] line2(Point p0,Point p1,double width){
117 :     Point v0=p1.minus(p0).rot270().normal(width);
118 :     Outline[] ret=new Outline[2];
119 :     OutlineComponent[] right=new OutlineComponent[1];
120 :     right[0]=new Line(p0.plus(v0),p1.plus(v0));
121 :     OutlineComponent[] left=new OutlineComponent[1];
122 :     left[0]=new Line(p0.minus(v0),p1.minus(v0));
123 :     ret[0]=new Outline(right);
124 :     ret[1]=new Outline(left);
125 :     return ret;
126 :     }
127 :     //
128 :     public Outline curveSub(Point p0, Point p1, Point p2, Point p3,
129 :     double r0, double r1){
130 :     OutlineComponent[] ret=new OutlineComponent[1];
131 :     Point p12=Point.cross(p0,p1,p2,p3);
132 :     if(debug)
133 :     System.out.println("cross("+p0+","+p1+","+p2+","+p3+")="+p12);
134 :     ret[0]=new Bezier(p0,p0.inter(p12,r0),p3.inter(p12,r1),p3);
135 :     return new Outline(ret);
136 :     }
137 :     // p0, p1, p2$B$N4V$r6J@~$G7k$V(B
138 :     // p0 $B$G$OI}(B w0, p2$B$G$OI}(Bw3
139 :     // p0$B$+$i(B p1$B$K(Br0(0$B$+$i(B1)$B?J$s$@$H$3$m$GI}(B w1
140 :     // p2$B$+$i(B r1(0$B$+$i(B1)$BLa$C$?$H$3$m$GI}(B w2$B$H$J$k(B
141 :     // $B$?$@$7(B, $B30B&$N%+!<%V$HFbB&$N%+!<%V$N(B Bezier$B@)8fE@$NHfN($,(B
142 :     // $BF1$8$K$J$k$h$&$K(B
143 :     public Outline[] curve2(Point p0,Point p1,Point p2,
144 :     double r0,double r1,
145 :     double w0,double w1,double w2,double w3){
146 :     Point p01=p0.inter(p1,r0),p12=p2.inter(p1,r1);
147 :     Outline[] ret=new Outline[2];
148 :     Point v0=p1.minus(p0).rot270(), v2=p2.minus(p0).rot270();
149 :     ret[0]=curveSub(p0.plus(v0.normal(w0)),
150 :     p0.inter(p1,r0).plus(v0.normal(w1)),
151 :     p2.inter(p1,r1).plus(v2.normal(w2)),
152 :     p2.plus(v2.normal(w3)),
153 :     r0,r1);
154 :     ret[1]=curveSub(p0.minus(v0.normal(w0)),
155 :     p0.inter(p1,r0).minus(v0.normal(w1)),
156 :     p2.inter(p1,r1).minus(v2.normal(w2)),
157 :     p2.minus(v2.normal(w3)),
158 :     r0,r1);
159 :     return ret;
160 :     }
161 : ktanaka 1.2 public Outline[] fitSample(Outline[] sample,Point p0, Point p1,double ratio){
162 :     Point p2=sample[0].firstPoint();
163 :     Point p3=sample[0].lastPoint();
164 :     double theta1=p3.minus(p2).theta();
165 :     double theta2=p1.minus(p0).theta();
166 :     double len01=p0.distance(p1),len23=p2.distance(p3);
167 :     double r1=len01/len23;
168 :     Outline[] ret=new Outline[2];
169 :     ret[0]=sample[0].plus(p2.neg()).rot(-theta1).times(r1).timesY(ratio).rot(theta2).plus(p0);
170 :     ret[1]=sample[1].plus(p2.neg()).rot(-theta1).times(r1).timesY(ratio).rot(theta2).plus(p0);
171 :     return ret;
172 :     }
173 : ktanaka 1.1 }
174 : ktanaka 1.2
175 :    
176 :    
177 :    

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help