]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/nonworking/freenote/freenote-1.6.1/compile.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / nonworking / freenote / freenote-1.6.1 / compile.patch
1
2 #
3 # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
4 #
5
6 --- FreeNote_1.6.1_arm/FmtEngine.cpp~compile    2003-12-23 15:53:46.000000000 +0100
7 +++ FreeNote_1.6.1_arm/FmtEngine.cpp    2004-02-01 18:42:32.000000000 +0100
8 @@ -1,409 +1,410 @@
9 -/*  FreeNote for Sharp SLA300, B500, C7x0 Linux PDA
10 -       Copyright (C) 2003 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
11 -
12 -    This program is free software; you can redistribute it and/or modify
13 -    it under the terms of the GNU General Public License as published by
14 -    the Free Software Foundation; either version 2 of the License, or
15 -    (at your option) any later version.
16 -
17 -    This program is distributed in the hope that it will be useful,
18 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
19 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 -    GNU General Public License for more details.
21 -
22 -    You should have received a copy of the GNU General Public License
23 -    along with this program; if not, write to the Free Software
24 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 -*/
26 -/*
27 -2003/12/16-19 FreeNote ver 1.5.5pre
28 -\81E\8bÈ\90ü\95`\89æ\83\8d\83W\83b\83N\82Ì\89ü\97Ç
29 -
30 -2003/12/14 FreeNote 1.5.4pre
31 -\81E\8bÈ\90ü\95`\89æ\83\8d\83W\83b\83N\82Ì\89ü\97Ç
32 -
33 -2003/11/30-2003/12/04 FreeNote 1.5.3pre
34 -\81E\83x\83W\83F\8aÖ\90\94\82Ì\83X\83y\83\8b\83~\83X\82ð\8fC\90³
35 -
36 -2003/11/16 FreeNote 1.5.2pre
37 -\81E\89~\95`\89æ\82Ì\83\8d\83W\83b\83N\82ð\92Ç\89Á
38 -
39 -2003/11/13 FreeNote 1.5.1pre
40 -\81E\83X\83\80\81[\83W\83\93\83O\92Ç\89Á
41 -2003/11/10-12
42 -\81E\8bÈ\90ü\90®\8c`\83\82\81[\83h\92Ç\89Á
43 -2003/11/09 \92Ç\89Á
44 -*/
45 -#include "fmtengine.h"
46 -#include <qpointarray.h>
47 -#include <qpe/qmath.h>
48 -#include <math.h>
49 -int SNAP_SIZE = 32;
50 -int PHASE1_ANGLE = 30;
51 -int PHASE2_ANGLE = 30;
52 -double Surface(const QPoint& p1, const QPoint& p2)
53 -{
54 -       return 0.5 * abs(p1.x() * p2.y() - p1.y() * p2.x());
55 -}
56 -
57 -bool IsLinear(const QPoint& p1, const QPoint& p2, const QPoint& p3)
58 -{
59 -       double s1 = Surface(p1, p2);
60 -       double s2 = Surface(p2, p3);
61 -       double s3 = Surface(p1, p3);
62 -       if (s1 + s2 == s3) {
63 -               return true;
64 -       } else {
65 -               return false;
66 -       }
67 -}
68 -
69 -const double Angle(const QPoint& p1, const QPoint& p2)
70 -{
71 -       return qATan2((double)(p2.y() - p1.y()), (double)(p2.x() - p1.x()));
72 -}
73 -
74 -const double DiffAngle(const QPoint& p1, const QPoint& p2, const QPoint& p3)
75 -{
76 -       return fabs(Angle(p1, p2) - Angle(p2, p3));
77 -}
78 -
79 -const double ToDegree(double t)
80 -{
81 -       return t * 180 / M_PI;
82 -}
83 -
84 -const double ToRadian(double d)
85 -{
86 -       return d * M_PI / 180;
87 -}
88 -
89 -const double Distance(const QPoint& p1, const QPoint& p2)
90 -{
91 -       return hypot(p1.x() - p2.x(), p1.y() - p2.y());
92 -}
93 -
94 -const QPoint SnapPoint(const QPoint& p)
95 -{
96 -       int x = ((int)(p.x() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
97 -       int y = ((int)(p.y() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
98 -       return QPoint(x, y);
99 -}
100 -
101 -const QPoint ArrangePoint(const QPoint& p1, const QPoint& p2)
102 -{
103 -       int x = p2.x();
104 -       int y = p2.y();
105 -       if (p1.x() - SNAP_SIZE / 2 <= x && p1.x() + SNAP_SIZE / 2 >= x) {
106 -               x = p1.x();
107 -       }
108 -       if (p1.y() - SNAP_SIZE / 2 <= y && p1.y() + SNAP_SIZE / 2 >= y) {
109 -               y = p1.y();
110 -       }
111 -       return QPoint(x, y);
112 -}
113 -
114 -FNPointList ReducePoints(FNPointList& p)
115 -{
116 -       if (3 >= p.count()) {
117 -               return p;
118 -       }
119 -       FNPointList rt;
120 -       rt.append(p.first());
121 -       QPoint* p1 = p.first();
122 -       QPoint* p2 = p.at(1);
123 -       QPoint* p3 = NULL;
124 -       for (uint i = 2; i < p.count(); ++i) {
125 -               p3 = p.at(i);
126 -               if (false == IsLinear(*p1, *p2, *p3)) {
127 -                       rt.append(p2);
128 -                       p1 = p2;
129 -               }
130 -               p2 = p3;
131 -       }
132 -       rt.append(p3);
133 -       return rt;
134 -}
135 -
136 -FNPointList ExtractAngle2(FNPointList& p, const int deg)
137 -{
138 -       FNPointList rt;
139 -       rt.append(p.first());
140 -       QPoint* st = p.first();
141 -       QPoint* mp = p.at(1);
142 -       QPoint* ed = p.last();
143 -       for (uint i = 2; i < p.count(); ++i) {
144 -               ed = p.at(i);
145 -               if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
146 -                       st = mp;
147 -                       rt.append(mp);
148 -               }
149 -               mp = ed;
150 -       }
151 -       rt.append(ed);
152 -       return rt;
153 -}
154 -
155 -FNPointList ExtractAngle(FNPointList& p, const int deg)
156 -{
157 -       FNPointList rt;
158 -       rt.append(p.first());
159 -       QPoint* st = p.first();
160 -       QPoint* mp = p.at(1);
161 -       QPoint* ed = p.last();
162 -       for (uint i = 2; i < p.count(); ++i) {
163 -               ed = p.at(i);
164 -               if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
165 -                       st = mp;
166 -                       rt.append(mp); 
167 -               }
168 -               mp = ed;
169 -       }
170 -       if (SNAP_SIZE / 2 > Distance(*p.first(), *p.last()) && 3 < p.count()) {
171 -               rt.append(p.first());
172 -       } else {
173 -               rt.append(ed);
174 -       }
175 -       return rt;
176 -}
177 -
178 -FNPointList SumupPoints(FNPointList& p)
179 -{
180 -       if (3 >= p.count()) {
181 -               return p;
182 -       }
183 -       FNPointList rt;
184 -       rt.append(p.first());
185 -       QPoint* p1 = p.first();
186 -       QPoint* p2 = NULL;
187 -       double pred = 0;
188 -       for (uint i = 1; i < p.count() - 1; ++i) {
189 -               p2 = p.at(i);
190 -               double d = Distance(*p1, *p2);
191 -               if (SNAP_SIZE / 2 < d || pred > d) {
192 -                       rt.append(p2);
193 -                       p1 = p2;
194 -                       d = 0;
195 -               }
196 -               pred = d;
197 -       }
198 -       rt.append(p.last());
199 -       return rt;
200 -}
201 -
202 -FNPointList SnapPoints(FNPointList& p)
203 -{
204 -       FNPointList rt;
205 -       for (uint i = 0; i < p.count(); ++i) {
206 -               QPoint tp = SnapPoint(*p.at(i));
207 -               p.at(i)->setX(tp.x());
208 -               p.at(i)->setY(tp.y());
209 -               rt.append(p.at(i));
210 -       }
211 -       return rt;
212 -}
213 -
214 -FNPointList ArrangePoints(FNPointList& p)
215 -{
216 -       if (3 >= p.count() && 2 != p.count()) {
217 -               return p;
218 -       }
219 -       FNPointList rt;
220 -       rt.append(p.first());
221 -       QPoint* p1 = p.first();
222 -       QPoint* p2 = NULL;
223 -       for (uint i = 1; i < p.count(); ++i) {
224 -               p2 = p.at(i);
225 -               QPoint tp = ArrangePoint(*p1, *p2);
226 -               p2->setX(tp.x());
227 -               p2->setY(tp.y());
228 -               rt.append(p2);
229 -               p1 = p2;
230 -       }
231 -       if (*p.first() == *p.last()) {
232 -               QPoint tp = ArrangePoint(*p1, *p.first());
233 -               rt.first()->setX(tp.x());
234 -               rt.first()->setY(tp.y());
235 -       }
236 -       return rt;
237 -}
238 -
239 -FNPointList TuningPoints(FNPointList& p)
240 -{
241 -       FNPointList rt;
242 -       if (3 >= p.count()) {
243 -               for (uint i = 0; i < p.count(); ++i) {
244 -                       rt.append(new QPoint(*p.at(i)));
245 -               }
246 -               return rt;
247 -       }
248 -       rt.append(new QPoint(*p.at(0)));
249 -       for (uint i = 1; i < p.count() - 1; ++i) {
250 -               QPoint* p1 = p.at(i);
251 -               QPoint* p2 = p.at(i + 1);
252 -               rt.append(new QPoint(*p1));
253 -               if (i < p.count() - 2) {
254 -                       rt.append(new QPoint((p1->x() + p2->x())/2, (p1->y() + p2->y())/2));
255 -               }
256 -       }
257 -       rt.append(new QPoint(*p.at(p.count()-1)));
258 -       return rt;
259 -}
260 -
261 -FNPointList ToBezier(FNPointList& p) {
262 -       FNPointList rt;
263 -       rt.append(new QPoint(*p.at(0)));
264 -       for (uint i = 0; i < p.count() - 2; i += 2) {
265 -               int x1 = p.at(i)->x();
266 -               int xa = p.at(i + 1)->x();
267 -               int x4 = p.at(i + 2)->x();
268 -
269 -               int x2 = (x1 + xa) / 2;
270 -               int x3 = (xa + x4) / 2;
271 -               
272 -               int y1 = p.at(i)->y();
273 -               int ya = p.at(i + 1)->y();
274 -               int y4 = p.at(i + 2)->y();
275 -
276 -               int y2 = (y1 + ya) / 2;
277 -               int y3 = (ya + y4) / 2;
278 -               
279 -               rt.append(new QPoint(x2 ,y2));
280 -               rt.append(new QPoint(x3 ,y3));
281 -               rt.append(new QPoint(x4 ,y4));
282 -       }
283 -       return rt;
284 -}
285 -
286 -FNPointList ToCurves(FNPointList& p) {
287 -       if (3 <= p.count()) {
288 -               //\83x\83W\83F\82É\82æ\82é\95â\8a® 
289 -               return ToBezier(p);
290 -       } else {
291 -               FNPointList rt;
292 -               for (uint i = 0; i < p.count(); ++i) {
293 -                       rt.append(new QPoint(*p.at(i)));
294 -               }
295 -               return rt;
296 -       }
297 -}
298 -
299 -FNPointList AutoFormat(FNPointList& p)
300 -{
301 -       FNPointList tp = ExtractAngle(p, PHASE1_ANGLE);
302 -       uint n;
303 -       do {
304 -               n = tp.count();
305 -               tp = SumupPoints(tp);
306 -               tp = ExtractAngle(tp, PHASE1_ANGLE);
307 -               tp = ArrangePoints(tp);
308 -       } while (n > tp.count());
309 -       tp = SnapPoints(tp);
310 -       tp = ReducePoints(tp);
311 -       FNPointList rt;
312 -       if (2 == tp.count()) {
313 -               if (*tp.first() == *tp.last()) {
314 -                       return rt;
315 -               }
316 -       }
317 -       for (uint i = 0; i < tp.count(); ++i) {
318 -               rt.append(new QPoint(*tp.at(i)));
319 -       }
320 -       return rt;
321 -}
322 -
323 -FNPointList ToEllipse(int x, int y, int w, int h) {
324 -       FNPointList rt;
325 -       QPointArray pa;
326 -       pa.makeEllipse(x, y, w, h);
327 -       for (uint i = 0; i < pa.count(); ++i) {
328 -               rt.append(new QPoint(pa.point(i)));
329 -       }
330 -       return rt;
331 -}
332 -
333 -FNPointList AutoCurve(FNPointList& p)
334 -{
335 -       FNPointList tp2;
336 -       tp2.setAutoDelete(true); 
337 -       FNPointList tp4;
338 -       tp4.setAutoDelete(true); 
339 -       QPoint sp = SnapPoint(*p.at(0));
340 -       QPoint ep = SnapPoint(*p.at(p.count()-1));
341 -       if (sp == ep) {
342 -               //\91È\89~
343 -               int sx = p.at(0)->x();
344 -               int sy = p.at(0)->y();
345 -               int ex = sx;
346 -               int ey = sy;
347 -               for (uint i = 1; i < p.count(); ++i) {
348 -                       QPoint tp = *p.at(i);
349 -                       if (sx > tp.x()) {
350 -                               sx = tp.x();
351 -                       } else if (ex < tp.x()) {
352 -                               ex = tp.x();
353 -                       }
354 -                       if (sy > tp.y()) {
355 -                               sy = tp.y();
356 -                       } else if (ey < tp.y()) {
357 -                               ey = tp.y();
358 -                       }
359 -               }
360 -               sp = SnapPoint(QPoint(sx, sy));
361 -               ep = SnapPoint(QPoint(ex, ey));
362 -               tp2.append(new QPoint(sp.x(), sp.y()));
363 -               tp2.append(new QPoint(ep.x(), ep.y()));
364 -       } else {
365 -               FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE);
366 -               uint n;
367 -               do {
368 -                       n = tp.count();
369 -                       tp = SumupPoints(tp);
370 -                       tp = ExtractAngle2(tp, PHASE2_ANGLE);
371 -                       tp = SnapPoints(tp);
372 -               } while (n > tp.count());
373 -               tp = SumupPoints(tp);
374 -               tp = ReducePoints(tp);
375 -               tp4 = TuningPoints(tp);
376 -               tp2 = ToCurves(tp4);
377 -       }
378 -       FNPointList rt;
379 -       if (2 == tp2.count()) {
380 -               if (*tp2.first() == *tp2.last()) { 
381 -                       return rt;
382 -               }
383 -       }
384 -       for (uint i = 0; i < tp2.count(); ++i) {
385 -               rt.append(new QPoint(*tp2.at(i))); 
386 -       }
387 -       return rt;
388 -}
389 -
390 -FNPointList Smoothing(FNPointList& p)
391 -{
392 -       int tsnap = SNAP_SIZE;
393 -       SNAP_SIZE=8;
394 -       FNPointList tp = ExtractAngle2(p,  PHASE2_ANGLE);
395 -       tp = SumupPoints(tp);
396 -       tp = ReducePoints(tp);
397 -       FNPointList tp4 = TuningPoints(tp);
398 -       tp4.setAutoDelete(true);
399 -       FNPointList tp2 = ToCurves(tp4);
400 -       tp2.setAutoDelete(true);
401 -       FNPointList rt;
402 -       for (uint i = 0; i < tp2.count(); ++i) {
403 -               rt.append(new QPoint(*tp2.at(i))); 
404 -       }
405 -       SNAP_SIZE = tsnap;
406 -       return rt;
407 -}
408 -
409 -FNPointList Reduce(FNPointList& p)
410 -{
411 -       FNPointList tp = ReducePoints(p);
412 -       FNPointList rt;
413 -       for (uint i = 0; i < tp.count(); ++i) {
414 -               rt.append(new QPoint(*tp.at(i))); 
415 -       }
416 -       return rt;
417 -}
418 +/*  FreeNote for Sharp SLA300, B500, C7x0 Linux PDA
419 +       Copyright (C) 2003 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
420 +
421 +    This program is free software; you can redistribute it and/or modify
422 +    it under the terms of the GNU General Public License as published by
423 +    the Free Software Foundation; either version 2 of the License, or
424 +    (at your option) any later version.
425 +
426 +    This program is distributed in the hope that it will be useful,
427 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
428 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
429 +    GNU General Public License for more details.
430 +
431 +    You should have received a copy of the GNU General Public License
432 +    along with this program; if not, write to the Free Software
433 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
434 +*/
435 +/*
436 +2003/12/16-19 FreeNote ver 1.5.5pre
437 +\81E\8bÈ\90ü\95`\89æ\83\8d\83W\83b\83N\82Ì\89ü\97Ç
438 +
439 +2003/12/14 FreeNote 1.5.4pre
440 +\81E\8bÈ\90ü\95`\89æ\83\8d\83W\83b\83N\82Ì\89ü\97Ç
441 +
442 +2003/11/30-2003/12/04 FreeNote 1.5.3pre
443 +\81E\83x\83W\83F\8aÖ\90\94\82Ì\83X\83y\83\8b\83~\83X\82ð\8fC\90³
444 +
445 +2003/11/16 FreeNote 1.5.2pre
446 +\81E\89~\95`\89æ\82Ì\83\8d\83W\83b\83N\82ð\92Ç\89Á
447 +
448 +2003/11/13 FreeNote 1.5.1pre
449 +\81E\83X\83\80\81[\83W\83\93\83O\92Ç\89Á
450 +2003/11/10-12
451 +\81E\8bÈ\90ü\90®\8c`\83\82\81[\83h\92Ç\89Á
452 +2003/11/09 \92Ç\89Á
453 +*/
454 +#include "fmtengine.h"
455 +#include <qpointarray.h>
456 +#include <qpe/qmath.h>
457 +#include <math.h>
458 +#include <stdlib.h> // abs
459 +int SNAP_SIZE = 32;
460 +int PHASE1_ANGLE = 30;
461 +int PHASE2_ANGLE = 30;
462 +double Surface(const QPoint& p1, const QPoint& p2)
463 +{
464 +       return 0.5 * abs(p1.x() * p2.y() - p1.y() * p2.x());
465 +}
466 +
467 +bool IsLinear(const QPoint& p1, const QPoint& p2, const QPoint& p3)
468 +{
469 +       double s1 = Surface(p1, p2);
470 +       double s2 = Surface(p2, p3);
471 +       double s3 = Surface(p1, p3);
472 +       if (s1 + s2 == s3) {
473 +               return true;
474 +       } else {
475 +               return false;
476 +       }
477 +}
478 +
479 +const double Angle(const QPoint& p1, const QPoint& p2)
480 +{
481 +       return qATan2((double)(p2.y() - p1.y()), (double)(p2.x() - p1.x()));
482 +}
483 +
484 +const double DiffAngle(const QPoint& p1, const QPoint& p2, const QPoint& p3)
485 +{
486 +       return fabs(Angle(p1, p2) - Angle(p2, p3));
487 +}
488 +
489 +const double ToDegree(double t)
490 +{
491 +       return t * 180 / M_PI;
492 +}
493 +
494 +const double ToRadian(double d)
495 +{
496 +       return d * M_PI / 180;
497 +}
498 +
499 +const double Distance(const QPoint& p1, const QPoint& p2)
500 +{
501 +       return hypot(p1.x() - p2.x(), p1.y() - p2.y());
502 +}
503 +
504 +const QPoint SnapPoint(const QPoint& p)
505 +{
506 +       int x = ((int)(p.x() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
507 +       int y = ((int)(p.y() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
508 +       return QPoint(x, y);
509 +}
510 +
511 +const QPoint ArrangePoint(const QPoint& p1, const QPoint& p2)
512 +{
513 +       int x = p2.x();
514 +       int y = p2.y();
515 +       if (p1.x() - SNAP_SIZE / 2 <= x && p1.x() + SNAP_SIZE / 2 >= x) {
516 +               x = p1.x();
517 +       }
518 +       if (p1.y() - SNAP_SIZE / 2 <= y && p1.y() + SNAP_SIZE / 2 >= y) {
519 +               y = p1.y();
520 +       }
521 +       return QPoint(x, y);
522 +}
523 +
524 +FNPointList ReducePoints(FNPointList& p)
525 +{
526 +       if (3 >= p.count()) {
527 +               return p;
528 +       }
529 +       FNPointList rt;
530 +       rt.append(p.first());
531 +       QPoint* p1 = p.first();
532 +       QPoint* p2 = p.at(1);
533 +       QPoint* p3 = NULL;
534 +       for (uint i = 2; i < p.count(); ++i) {
535 +               p3 = p.at(i);
536 +               if (false == IsLinear(*p1, *p2, *p3)) {
537 +                       rt.append(p2);
538 +                       p1 = p2;
539 +               }
540 +               p2 = p3;
541 +       }
542 +       rt.append(p3);
543 +       return rt;
544 +}
545 +
546 +FNPointList ExtractAngle2(FNPointList& p, const int deg)
547 +{
548 +       FNPointList rt;
549 +       rt.append(p.first());
550 +       QPoint* st = p.first();
551 +       QPoint* mp = p.at(1);
552 +       QPoint* ed = p.last();
553 +       for (uint i = 2; i < p.count(); ++i) {
554 +               ed = p.at(i);
555 +               if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
556 +                       st = mp;
557 +                       rt.append(mp);
558 +               }
559 +               mp = ed;
560 +       }
561 +       rt.append(ed);
562 +       return rt;
563 +}
564 +
565 +FNPointList ExtractAngle(FNPointList& p, const int deg)
566 +{
567 +       FNPointList rt;
568 +       rt.append(p.first());
569 +       QPoint* st = p.first();
570 +       QPoint* mp = p.at(1);
571 +       QPoint* ed = p.last();
572 +       for (uint i = 2; i < p.count(); ++i) {
573 +               ed = p.at(i);
574 +               if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
575 +                       st = mp;
576 +                       rt.append(mp); 
577 +               }
578 +               mp = ed;
579 +       }
580 +       if (SNAP_SIZE / 2 > Distance(*p.first(), *p.last()) && 3 < p.count()) {
581 +               rt.append(p.first());
582 +       } else {
583 +               rt.append(ed);
584 +       }
585 +       return rt;
586 +}
587 +
588 +FNPointList SumupPoints(FNPointList& p)
589 +{
590 +       if (3 >= p.count()) {
591 +               return p;
592 +       }
593 +       FNPointList rt;
594 +       rt.append(p.first());
595 +       QPoint* p1 = p.first();
596 +       QPoint* p2 = NULL;
597 +       double pred = 0;
598 +       for (uint i = 1; i < p.count() - 1; ++i) {
599 +               p2 = p.at(i);
600 +               double d = Distance(*p1, *p2);
601 +               if (SNAP_SIZE / 2 < d || pred > d) {
602 +                       rt.append(p2);
603 +                       p1 = p2;
604 +                       d = 0;
605 +               }
606 +               pred = d;
607 +       }
608 +       rt.append(p.last());
609 +       return rt;
610 +}
611 +
612 +FNPointList SnapPoints(FNPointList& p)
613 +{
614 +       FNPointList rt;
615 +       for (uint i = 0; i < p.count(); ++i) {
616 +               QPoint tp = SnapPoint(*p.at(i));
617 +               p.at(i)->setX(tp.x());
618 +               p.at(i)->setY(tp.y());
619 +               rt.append(p.at(i));
620 +       }
621 +       return rt;
622 +}
623 +
624 +FNPointList ArrangePoints(FNPointList& p)
625 +{
626 +       if (3 >= p.count() && 2 != p.count()) {
627 +               return p;
628 +       }
629 +       FNPointList rt;
630 +       rt.append(p.first());
631 +       QPoint* p1 = p.first();
632 +       QPoint* p2 = NULL;
633 +       for (uint i = 1; i < p.count(); ++i) {
634 +               p2 = p.at(i);
635 +               QPoint tp = ArrangePoint(*p1, *p2);
636 +               p2->setX(tp.x());
637 +               p2->setY(tp.y());
638 +               rt.append(p2);
639 +               p1 = p2;
640 +       }
641 +       if (*p.first() == *p.last()) {
642 +               QPoint tp = ArrangePoint(*p1, *p.first());
643 +               rt.first()->setX(tp.x());
644 +               rt.first()->setY(tp.y());
645 +       }
646 +       return rt;
647 +}
648 +
649 +FNPointList TuningPoints(FNPointList& p)
650 +{
651 +       FNPointList rt;
652 +       if (3 >= p.count()) {
653 +               for (uint i = 0; i < p.count(); ++i) {
654 +                       rt.append(new QPoint(*p.at(i)));
655 +               }
656 +               return rt;
657 +       }
658 +       rt.append(new QPoint(*p.at(0)));
659 +       for (uint i = 1; i < p.count() - 1; ++i) {
660 +               QPoint* p1 = p.at(i);
661 +               QPoint* p2 = p.at(i + 1);
662 +               rt.append(new QPoint(*p1));
663 +               if (i < p.count() - 2) {
664 +                       rt.append(new QPoint((p1->x() + p2->x())/2, (p1->y() + p2->y())/2));
665 +               }
666 +       }
667 +       rt.append(new QPoint(*p.at(p.count()-1)));
668 +       return rt;
669 +}
670 +
671 +FNPointList ToBezier(FNPointList& p) {
672 +       FNPointList rt;
673 +       rt.append(new QPoint(*p.at(0)));
674 +       for (uint i = 0; i < p.count() - 2; i += 2) {
675 +               int x1 = p.at(i)->x();
676 +               int xa = p.at(i + 1)->x();
677 +               int x4 = p.at(i + 2)->x();
678 +
679 +               int x2 = (x1 + xa) / 2;
680 +               int x3 = (xa + x4) / 2;
681 +               
682 +               int y1 = p.at(i)->y();
683 +               int ya = p.at(i + 1)->y();
684 +               int y4 = p.at(i + 2)->y();
685 +
686 +               int y2 = (y1 + ya) / 2;
687 +               int y3 = (ya + y4) / 2;
688 +               
689 +               rt.append(new QPoint(x2 ,y2));
690 +               rt.append(new QPoint(x3 ,y3));
691 +               rt.append(new QPoint(x4 ,y4));
692 +       }
693 +       return rt;
694 +}
695 +
696 +FNPointList ToCurves(FNPointList& p) {
697 +       if (3 <= p.count()) {
698 +               //\83x\83W\83F\82É\82æ\82é\95â\8a® 
699 +               return ToBezier(p);
700 +       } else {
701 +               FNPointList rt;
702 +               for (uint i = 0; i < p.count(); ++i) {
703 +                       rt.append(new QPoint(*p.at(i)));
704 +               }
705 +               return rt;
706 +       }
707 +}
708 +
709 +FNPointList AutoFormat(FNPointList& p)
710 +{
711 +       FNPointList tp = ExtractAngle(p, PHASE1_ANGLE);
712 +       uint n;
713 +       do {
714 +               n = tp.count();
715 +               tp = SumupPoints(tp);
716 +               tp = ExtractAngle(tp, PHASE1_ANGLE);
717 +               tp = ArrangePoints(tp);
718 +       } while (n > tp.count());
719 +       tp = SnapPoints(tp);
720 +       tp = ReducePoints(tp);
721 +       FNPointList rt;
722 +       if (2 == tp.count()) {
723 +               if (*tp.first() == *tp.last()) {
724 +                       return rt;
725 +               }
726 +       }
727 +       for (uint i = 0; i < tp.count(); ++i) {
728 +               rt.append(new QPoint(*tp.at(i)));
729 +       }
730 +       return rt;
731 +}
732 +
733 +FNPointList ToEllipse(int x, int y, int w, int h) {
734 +       FNPointList rt;
735 +       QPointArray pa;
736 +       pa.makeEllipse(x, y, w, h);
737 +       for (uint i = 0; i < pa.count(); ++i) {
738 +               rt.append(new QPoint(pa.point(i)));
739 +       }
740 +       return rt;
741 +}
742 +
743 +FNPointList AutoCurve(FNPointList& p)
744 +{
745 +       FNPointList tp2;
746 +       tp2.setAutoDelete(true); 
747 +       FNPointList tp4;
748 +       tp4.setAutoDelete(true); 
749 +       QPoint sp = SnapPoint(*p.at(0));
750 +       QPoint ep = SnapPoint(*p.at(p.count()-1));
751 +       if (sp == ep) {
752 +               //\91È\89~
753 +               int sx = p.at(0)->x();
754 +               int sy = p.at(0)->y();
755 +               int ex = sx;
756 +               int ey = sy;
757 +               for (uint i = 1; i < p.count(); ++i) {
758 +                       QPoint tp = *p.at(i);
759 +                       if (sx > tp.x()) {
760 +                               sx = tp.x();
761 +                       } else if (ex < tp.x()) {
762 +                               ex = tp.x();
763 +                       }
764 +                       if (sy > tp.y()) {
765 +                               sy = tp.y();
766 +                       } else if (ey < tp.y()) {
767 +                               ey = tp.y();
768 +                       }
769 +               }
770 +               sp = SnapPoint(QPoint(sx, sy));
771 +               ep = SnapPoint(QPoint(ex, ey));
772 +               tp2.append(new QPoint(sp.x(), sp.y()));
773 +               tp2.append(new QPoint(ep.x(), ep.y()));
774 +       } else {
775 +               FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE);
776 +               uint n;
777 +               do {
778 +                       n = tp.count();
779 +                       tp = SumupPoints(tp);
780 +                       tp = ExtractAngle2(tp, PHASE2_ANGLE);
781 +                       tp = SnapPoints(tp);
782 +               } while (n > tp.count());
783 +               tp = SumupPoints(tp);
784 +               tp = ReducePoints(tp);
785 +               tp4 = TuningPoints(tp);
786 +               tp2 = ToCurves(tp4);
787 +       }
788 +       FNPointList rt;
789 +       if (2 == tp2.count()) {
790 +               if (*tp2.first() == *tp2.last()) { 
791 +                       return rt;
792 +               }
793 +       }
794 +       for (uint i = 0; i < tp2.count(); ++i) {
795 +               rt.append(new QPoint(*tp2.at(i))); 
796 +       }
797 +       return rt;
798 +}
799 +
800 +FNPointList Smoothing(FNPointList& p)
801 +{
802 +       int tsnap = SNAP_SIZE;
803 +       SNAP_SIZE=8;
804 +       FNPointList tp = ExtractAngle2(p,  PHASE2_ANGLE);
805 +       tp = SumupPoints(tp);
806 +       tp = ReducePoints(tp);
807 +       FNPointList tp4 = TuningPoints(tp);
808 +       tp4.setAutoDelete(true);
809 +       FNPointList tp2 = ToCurves(tp4);
810 +       tp2.setAutoDelete(true);
811 +       FNPointList rt;
812 +       for (uint i = 0; i < tp2.count(); ++i) {
813 +               rt.append(new QPoint(*tp2.at(i))); 
814 +       }
815 +       SNAP_SIZE = tsnap;
816 +       return rt;
817 +}
818 +
819 +FNPointList Reduce(FNPointList& p)
820 +{
821 +       FNPointList tp = ReducePoints(p);
822 +       FNPointList rt;
823 +       for (uint i = 0; i < tp.count(); ++i) {
824 +               rt.append(new QPoint(*tp.at(i))); 
825 +       }
826 +       return rt;
827 +}
828 --- FreeNote_1.6.1_arm/FNCanvas.cpp~compile     2003-12-24 15:20:16.000000000 +0100
829 +++ FreeNote_1.6.1_arm/FNCanvas.cpp     2004-02-01 18:43:35.000000000 +0100
830 @@ -1,1227 +1,1228 @@
831 -/*  FreeNote for Sharp SLA300, B500, C7x0 Linux PDA
832 -       Copyright (C) 2003 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
833 -
834 -    This program is free software; you can redistribute it and/or modify
835 -    it under the terms of the GNU General Public License as published by
836 -    the Free Software Foundation; either version 2 of the License, or
837 -    (at your option) any later version.
838 -
839 -    This program is distributed in the hope that it will be useful,
840 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
841 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
842 -    GNU General Public License for more details.
843 -
844 -    You should have received a copy of the GNU General Public License
845 -    along with this program; if not, write to the Free Software
846 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
847 -*/
848 -/*
849 -2003/12/23 ver 1.6.1
850 -\81E\95Û\91\8fî\95ñ\82Ì\83T\83C\83Y\8fk\8f¬
851 -
852 -2003/12/16-19 ver 1.5.5pre
853 -\81E\83y\83\93\83T\83C\83Y\82Ì\92Ç\89Á(1-8)
854 -\81E\83A\83\93\83h\83D\81E\83\8a\83h\83D\82Ì\8eÀ\91\95
855 -
856 -2003/12/14 ver 1.5.4pre
857 -\81E\83y\83\93\83T\83C\83Y\82ð\91I\91ð\89Â\94\\82É\81B
858 -
859 -2003/12/05 ver 1.5.3Apre
860 -\81E\83O\83\8a\83b\83h\82Ì\90F\82ð\8fC\90³
861 -
862 -2003/12/04 ver 1.5.3pre
863 -\81E\83O\83\8a\83b\83h\82Ì\95`\89æ\82ð\88ê\95\94\8fC\90³
864 -
865 -2003/11/10 ver 1.5.1pre
866 -\81E\8bÈ\90ü\90®\8c`\83\82\81[\83h\92Ç\89Á
867 -
868 -2003/11/09 ver 1.5.0pre
869 -\81E\8e©\93®\90®\8c`\83\82\81[\83h\92Ç\89Á
870 -
871 -2003/09/03 ver 1.3.4pre
872 -\81EUse all quadrant OFF\8e\9e\82É\95\\8e¦\88Ê\92u\82ª\83\8a\83Z\83b\83g\82³\82ê\82é\8fê\8d\87\82ª\82 \82é\83o\83O\91Î\89\9e\81B
873 -
874 -2003/09/01-03 ver 1.3.3pre
875 -\81E\83X\83N\83\8d\81[\83\8b\82Ì\89ü\97Ç
876 -\81EUse all quadrant(\91S\8fÛ\8cÀ\82ð\8eg\97p\82·\82é)\83\81\83j\83\85\81[\82ð\92Ç\89Á
877 -
878 -2003/08/31 FreeNote 1.3.2pre
879 -\81E\91S\95û\8cü\83X\83N\83\8d\81[\83\8b
880 -
881 -2003/08/23 FreeNote 1.3.0pre
882 -\81ECR\93®\8dì\82Ì\8fC\90³
883 -
884 -2003/08/15 FreeNote 1.2.1\82ð\8cö\8aJ
885 -\81E\95Û\91\8e\9e\82Ì\83o\83O\8fC\90³
886 -\81E\8a®\97¹\83_\83C\83A\83\8d\83O\82Ì\8e©\93®\8fÁ\8b\8e
887 -\81EPNG\83t\83@\83C\83\8b\82Ö\82Ì\8fo\97Í
888 -
889 -2003/08/15 FreeNote 1.2\82ð\8cö\8aJ
890 -\81E\83I\83v\83V\83\87\83\93\92Ç\89Á
891 -\81E\83X\83N\83\8d\81[\83\8b\83K\83C\83h
892 -\81EFree\83t\83@\83C\83\8b\8aÖ\98A\95t\82¯
893 -\81E\83A\83C\83R\83\93\82Ì\95Ï\8dX
894 -
895 -2003/08/05 FreeNote 1.1.1pre\82ð\8cö\8aJ
896 -\81E\8d\82\91¬\8bN\93®\8e\9e\82É\95Â\82\82½\8fó\91Ô\82ð\95Û\8e\9d
897 -\81E\95`\89æ\83\82\81[\83h\90Ø\91Ö\82¦\8e\9e\82É\8fÁ\82µ\83S\83\80\95\\8e¦
898 -\81E\95Û\91\8e\9e\8aÔ\92Z\8fk
899 -\81EView\83\82\81[\83h\82Ì\8b\93\93®\82ð\95Ï\8dX
900 -\81E\83\81\83j\83\85\81[\82Ì\8c©\82½\96Ú\82ð\95Ï\8dX
901 -*/
902 -#include "fncanvas.h"
903 -#include <stdio.h>
904 -#include <qfile.h>
905 -#include <qmessagebox.h>
906 -#include <qtextstream.h>
907 -#include <qpen.h>
908 -#include <qcolor.h>
909 -#include <qpoint.h>
910 -#include <qthread.h>
911 -#include <qimage.h>
912 -#include <math.h>
913 -#include "fnmessagebox.h"
914 -#include "fmtengine.h"
915 -
916 -int snap(int v) {
917 -       int tv = abs(v);
918 -       tv = ((int)(tv + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
919 -       if (0 > v) {
920 -               return -tv;
921 -       } else {
922 -               return tv;
923 -       }
924 -}
925 -
926 -FNCanvas::FNCanvas(QWidget* parent = 0, const char* name = 0, WFlags f = 0)
927 -       :QWidget(parent, name, f),
928 -       _pen(black, 1, SolidLine, RoundCap, RoundJoin), 
929 -       _asMode(AS_NONE),
930 -       _drawMode(MODE_DRAW),
931 -       _disp_offset(0),
932 -       _eraser_l(50),
933 -       _eraser_s(10),
934 -       _h_step(100),
935 -       _v_step(100),
936 -       _margin(5),
937 -       _scrollTiming(800),
938 -       _viewMode(false),
939 -       _isWaiting(false),
940 -       _isDragging(false),
941 -       _isHeadingEnables(false),
942 -       _isShowGuide(false),
943 -       _isUseAllQuadrant(false),
944 -       _scale_x(1.0),
945 -       _scale_y(1.0)
946 -{
947 -       _tracks.setAutoDelete(true);
948 -       this->setBackgroundMode(NoBackground);
949 -       _timer = new QTimer(this);
950 -       connect(_timer, SIGNAL(timeout()), this, SLOT(autoScroll()));
951 -}
952 -
953 -FNCanvas::~FNCanvas()
954 -{
955 -       _timer->stop();
956 -       delete _timer;
957 -
958 -       _tracks.clear();
959 -       clearList(_draws);
960 -}
961 -
962 -void FNCanvas::setScrollTiming(int v)
963 -{
964 -       _scrollTiming = v;
965 -}
966 -
967 -
968 -void FNCanvas::setVStep(int v)
969 -{
970 -       _v_step = v;
971 -}
972 -
973 -void FNCanvas::setHStep(int v)
974 -{
975 -       _h_step = v;
976 -}
977 -
978 -void FNCanvas::setSEraser(int v)
979 -{
980 -       _eraser_s = v;
981 -}
982 -
983 -void FNCanvas::setLEraser(int v)
984 -{
985 -       _eraser_l = v;
986 -}
987 -
988 -
989 -void FNCanvas::setMargin(int v)
990 -{
991 -       if (v < 3) {
992 -               v = 3;
993 -       }
994 -       _margin = v;
995 -}
996 -
997 -void FNCanvas::setScrollMode(int as)
998 -{
999 -       _asMode = as;
1000 -       redraw();
1001 -}
1002 -
1003 -void FNCanvas::autoScroll()
1004 -{
1005 -       if (AS_NONE == _asMode) {
1006 -               if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_SMOOTH == _drawMode) {
1007 -                       setOrigin(_origin.x(), _origin.y());
1008 -               }
1009 -               return;
1010 -       }
1011 -       bool tmp = _isHeadingEnables;
1012 -       int dx = 0;
1013 -       int dy = 0;
1014 -       if (AS_BOTH == _asMode || AS_HORIZONTAL == _asMode) {
1015 -               if (_last.x() > width() * (_margin - 1) / _margin) {
1016 -                       dx = _h_step;
1017 -               } else if (_last.x() < width() / _margin) {
1018 -                       dx = -_h_step;
1019 -               }
1020 -       }
1021 -       if (AS_BOTH == _asMode || AS_VERTICAL == _asMode) {
1022 -               if (_last.y() > height() * (_margin - 1) / _margin) {
1023 -                       dy = _v_step;
1024 -               } else if (_last.y() < height() / _margin) {
1025 -                       dy = -_v_step;
1026 -               }
1027 -       }
1028 -       setOrigin(_origin.x() + dx, _origin.y() + dy);
1029 -       _isHeadingEnables = tmp;
1030 -}
1031 -
1032 -void FNCanvas::mousePressEvent(QMouseEvent* evt)
1033 -{
1034 -       setFocus();
1035 -       _timer->stop();
1036 -       _tracks.clear();
1037 -       if (_viewMode) {
1038 -               _isWaiting = true;
1039 -               _viewMode = false;
1040 -               setOrigin((int)((evt->x()) / _scale_x) - width() / 2, (int)((evt->y()) / _scale_y) - height() / 2);
1041 -               redraw();
1042 -               emit resetViewMode();
1043 -       } else if (MODE_ERASE != _drawMode) {
1044 -               _last = evt->pos();
1045 -               _tracks.append(new QPoint(_last));
1046 -       } else {
1047 -               redraw();
1048 -               _last = evt->pos();
1049 -               _tracks.append(new QPoint(_last));
1050 -
1051 -               QPainter pbuf;
1052 -               QPainter pwin;
1053 -               pbuf.begin(&_buffer);
1054 -               pwin.begin(this);
1055 -
1056 -               int w = _eraser_s;
1057 -               if (PENWIDTH_MAX / 2 < _pen.width()) {
1058 -                       w = _eraser_l;
1059 -               }
1060 -               pbuf.setRasterOp(XorROP);
1061 -               pbuf.setPen(QPen(white, 1));
1062 -               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1063 -
1064 -               pwin.setRasterOp(XorROP);
1065 -               pwin.setPen(QPen(white, 1));
1066 -               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1067 -
1068 -               pbuf.end();
1069 -               pwin.end();
1070 -       }
1071 -       _isDragging = true;
1072 -}
1073 -
1074 -void FNCanvas::mouseMoveEvent(QMouseEvent* evt)
1075 -{
1076 -       if (_isWaiting) {
1077 -               return;
1078 -       }
1079 -       if (MODE_ERASE != _drawMode) {
1080 -               QPainter pwin;
1081 -               QPainter pbuf;
1082 -               
1083 -               pwin.begin(this);
1084 -               pbuf.begin(&_buffer);
1085 -               
1086 -               pwin.setPen(_pen);
1087 -               pbuf.setPen(_pen);
1088 -               
1089 -               pwin.drawLine(_last, evt->pos());
1090 -               pbuf.drawLine(_last, evt->pos());
1091 -               
1092 -               pwin.end();
1093 -               pbuf.end();
1094 -               _last = evt->pos();
1095 -               _tracks.append(new QPoint(_last));
1096 -       } else {
1097 -               //redraw();
1098 -               if (_last.x() == -1) {
1099 -                       return;
1100 -               }
1101 -               QPainter pbuf;
1102 -               QPainter pwin;
1103 -               
1104 -               pbuf.begin(&_buffer);
1105 -               pwin.begin(this);
1106 -
1107 -               int w = _eraser_s;
1108 -               if (PENWIDTH_MAX / 2 < _pen.width()) {
1109 -                       w = _eraser_l;
1110 -               }
1111 -               pbuf.setRasterOp(XorROP);
1112 -               pwin.setRasterOp(XorROP);
1113 -               pbuf.setPen(QPen(white, 1));
1114 -               pwin.setPen(QPen(white, 1));
1115 -               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1116 -               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1117 -
1118 -               _tracks.append(new QPoint(evt->pos()));
1119 -               _last = evt->pos();
1120 -
1121 -               pbuf.setRasterOp(CopyROP);
1122 -               pwin.setRasterOp(CopyROP);
1123 -               QRect r = QRect(0, 0, width(), height());
1124 -               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1125 -                       FNPolygon* p = _draws.at(i);
1126 -                       if (r.intersects(p->boundingRect())) {
1127 -                               bool f = false;
1128 -                               QRect selected(_last.x() - w / 2, _last.y() - w / 2, w, w);
1129 -                               for (uint j = 0; j < p->points().count(); ++j) {
1130 -                                       QPoint& pts = p->points().at(j);
1131 -                                       if (selected.contains(pts)) {
1132 -                                               f = true;
1133 -                                               break;
1134 -                                       }
1135 -                               }
1136 -                               if (f) {
1137 -                                       p->drawShape(pbuf, f);
1138 -                                       p->drawShape(pwin, f);
1139 -                               }
1140 -                       }
1141 -               }
1142 -               pbuf.setRasterOp(XorROP);
1143 -               pwin.setRasterOp(XorROP);
1144 -               pbuf.setPen(QPen(white, 1));
1145 -               pwin.setPen(QPen(white, 1));
1146 -               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1147 -               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1148 -               pbuf.end();
1149 -               pwin.end();
1150 -       }
1151 -}
1152 -
1153 -void FNCanvas::mouseReleaseEvent(QMouseEvent* evt)
1154 -{
1155 -       _isDragging = false;
1156 -       if (_isWaiting) {
1157 -               _isWaiting = false;
1158 -               return;
1159 -       }
1160 -       _last = evt->pos();
1161 -       if (MODE_ERASE != _drawMode) {
1162 -               if (1 < _tracks.count()) {
1163 -                       FNPolygon* p = NULL;
1164 -                       if (MODE_FORMAT == _drawMode) {
1165 -                               p = new FNPolygon(_pen);
1166 -                               _tracks = AutoFormat(_tracks);
1167 -                       } else if (MODE_CURVE == _drawMode) {
1168 -                               QPoint sp = SnapPoint(*_tracks.at(0));
1169 -                               QPoint ep = SnapPoint(*_tracks.at(_tracks.count()-1));
1170 -                               _tracks = AutoCurve(_tracks);
1171 -                               if (sp == ep) {
1172 -                                       p = new FNEllipse(_pen);
1173 -                               } else if (2 < _tracks.count()) {
1174 -                                       p = new FNBezier(_pen);
1175 -                               } else {
1176 -                                       p = new FNPolygon(_pen);
1177 -                               }
1178 -                       } else if (MODE_SMOOTH == _drawMode) {
1179 -                               _tracks = Smoothing(_tracks);
1180 -                               if (2 < _tracks.count()) {
1181 -                                       p = new FNBezier(_pen);
1182 -                               } else {
1183 -                                       p = new FNPolygon(_pen);
1184 -                               }
1185 -                       } else {
1186 -                               _tracks = Reduce(_tracks);
1187 -                               p = new FNPolygon(_pen);
1188 -                       }
1189 -                       if (1 < _tracks.count()) {
1190 -                               p->setPoints(_tracks);
1191 -                               redobuf_flush();
1192 -                               _draws.append(p);
1193 -                       }
1194 -               }
1195 -               _tracks.clear();
1196 -               _isHeadingEnables = true;
1197 -               _timer->start(_scrollTiming, true);
1198 -       } else {
1199 -               _last = QPoint(-1, -1);
1200 -               _tracks.append(new QPoint(evt->pos()));
1201 -               redraw();
1202 -       }
1203 -}
1204 -
1205 -void FNCanvas::paintEvent(QPaintEvent* evt)
1206 -{
1207 -       bitBlt(this, 0, 0, &_buffer);
1208 -}
1209 -
1210 -void FNCanvas::resizeEvent(QResizeEvent* evt)
1211 -{
1212 -       QPixmap save(_buffer);
1213 -       _buffer.resize(evt->size());
1214 -       _buffer.fill(white);
1215 -       bitBlt(&_buffer, 0, 0, &save);
1216 -       redraw();
1217 -}
1218 -
1219 -void FNCanvas::setOrigin(QPoint& o)
1220 -{
1221 -       this->setOrigin(o.x(), o.y());
1222 -}
1223 -
1224 -QPoint FNCanvas::getTopLeft()
1225 -{
1226 -       if (0 == _draws.count() || !_isUseAllQuadrant) {
1227 -               return _origin;
1228 -       }
1229 -
1230 -       int dx = ((FNPolygon*)_draws.at(0))->boundingRect().x();
1231 -       int dy = ((FNPolygon*)_draws.at(0))->boundingRect().y();
1232 -       for (uint i = 1; i < _draws.count(); ++i) {
1233 -               FNPolygon* p = _draws.at(i);
1234 -               if (dx > p->boundingRect().x()) {
1235 -                       dx = p->boundingRect().x();
1236 -               }
1237 -               if (dy > p->boundingRect().y()) {
1238 -                       dy = p->boundingRect().y();
1239 -               }
1240 -       }
1241 -       return QPoint(snap(dx), snap(dy));
1242 -}
1243 -
1244 -
1245 -void FNCanvas::rebuild()
1246 -{
1247 -       if (0 == _draws.count() || !_isUseAllQuadrant) {
1248 -               return;
1249 -       }
1250 -
1251 -       QPoint d = getTopLeft();
1252 -       for (uint i = 0; i < _draws.count(); ++i) {
1253 -               FNPolygon* p = _draws.at(i);
1254 -               p->translate(-d.x(), -d.y());
1255 -       }
1256 -
1257 -       _origin = QPoint(0, 0);
1258 -}
1259 -
1260 -
1261 -void FNCanvas::setOrigin(int ox, int oy)
1262 -{
1263 -       ox = snap(ox);
1264 -       oy = snap(oy);
1265 -       _isHeadingEnables = false;
1266 -       _timer->stop();
1267 -
1268 -
1269 -       int dx = 0;
1270 -       int dy = 0;
1271 -       if (!_isUseAllQuadrant) {
1272 -               if (0 > ox) {
1273 -                       ox = 0;
1274 -               }
1275 -               if (0 > oy) {
1276 -                       oy = 0;
1277 -               }
1278 -               dx = _origin.x() - ox;
1279 -               dy = _origin.y() - oy;
1280 -       } else {
1281 -               dx = _origin.x() - ox;
1282 -               dy = _origin.y() - oy;
1283 -               if (0 > ox) {
1284 -                       ox = 0;
1285 -               }
1286 -               if (0 > oy) {
1287 -                       oy = 0;
1288 -               }
1289 -       }
1290 -       for (uint i = 0; i < _tracks.count(); ++i) {
1291 -               QPoint* p = _tracks.at(i);
1292 -               p->setX(p->x() + dx);
1293 -               p->setY(p->y() + dy);
1294 -       }
1295 -
1296 -       for (uint i = 0; i < _draws.count(); ++i) {
1297 -               FNPolygon* p = _draws.at(i);
1298 -               p->translate(dx, dy);
1299 -       }
1300 -       _origin = QPoint(ox, oy);
1301 -       emit originChanged(ox, oy);
1302 -       redraw();
1303 -}
1304 -
1305 -void FNCanvas::redraw()
1306 -{
1307 -       if (!this->isVisible()) {
1308 -               return;
1309 -       }
1310 -       _buffer.fill(white);
1311 -       QPainter pbuf;
1312 -       QRect r = QRect(0, 0, width(), height());
1313 -       pbuf.begin(&_buffer);
1314 -       if (_viewMode) {
1315 -               float wx = 0;
1316 -               float wy = 0;
1317 -               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1318 -                       FNPolygon* p = _draws.at(i);
1319 -                       QRect r = p->boundingRect();
1320 -                       if (wx < r.right()) {
1321 -                               wx = r.right();
1322 -                       } 
1323 -                       if (wy < r.bottom()) {
1324 -                               wy = r.bottom();
1325 -                       }
1326 -               }
1327 -               wx += SNAP_SIZE;
1328 -               wy += SNAP_SIZE;
1329 -               wx = snap((int)wx);
1330 -               wy = snap((int)wy);
1331 -               wx = wx + _origin.x();
1332 -               wy = wy + _origin.y();
1333 -               _scale_x = (float)width() / wx;
1334 -               _scale_y = (float)height() / wy;
1335 -               if (1.0f < _scale_x) { 
1336 -                       _scale_x = 1.0f;
1337 -               }
1338 -               if (1.0f < _scale_y) {
1339 -                       _scale_y = 1.0f;
1340 -               }
1341 -               if (_scale_x > _scale_y) {
1342 -                       _scale_x = _scale_y;
1343 -               } else if (_scale_x < _scale_y) {
1344 -                       _scale_y = _scale_x;
1345 -               }
1346 -               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1347 -                       FNPolygon* p = _draws.at(i);
1348 -                       FNPolygon* t = NULL;
1349 -                       if (p->type() == FN_BEZIER) {
1350 -                               t = new FNBezier(*(FNBezier*)p);
1351 -                       } else if (p->type() == FN_ELLIPSE) {
1352 -                               t = new FNEllipse(*(FNEllipse*)p);
1353 -                       } else {
1354 -                               t = new FNPolygon(*p);
1355 -                       }
1356 -                       t->translate(-_origin.x(), -_origin.y());
1357 -                       for (uint j = 0; j < t->points().count(); ++j) {
1358 -                               QPoint& pts = t->points().at(j);
1359 -                               int x = (int)(pts.x() * _scale_x);
1360 -                               int y = (int)(pts.y() * _scale_y);
1361 -                               pts.setX(x);
1362 -                               pts.setY(y);
1363 -                       }
1364 -                       double pensize = t->pen().width();
1365 -                       if (_scale_x > _scale_y) {
1366 -                               pensize = pensize * _scale_y;
1367 -                       } else {
1368 -                               pensize = pensize * _scale_x;
1369 -                       }
1370 -                       if (0 >= pensize) {
1371 -                               pensize = 1;
1372 -                       }
1373 -                       t->pen().setWidth(pensize);
1374 -                       t->drawShape(pbuf);
1375 -                       delete t;
1376 -               }
1377 -       } else if (MODE_ERASE != _drawMode) {
1378 -               if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode) {
1379 -                       QPen pen1(QColor(0, 240, 240), 1);
1380 -                       QPen pen2(QColor(0, 0, 0), 1);
1381 -                       pbuf.setPen(QPen(QColor(0, 240, 240), 1));
1382 -                       pbuf.setPen(pen1);
1383 -                       for (int x = 0; x < width() + SNAP_SIZE; x += SNAP_SIZE) {
1384 -                               pbuf.drawLine(x - SNAP_SIZE / 2, 0, x - SNAP_SIZE / 2, height());
1385 -                               for (int y = 0; y < height() + SNAP_SIZE; y += SNAP_SIZE) {
1386 -                                       pbuf.drawLine(0, y - SNAP_SIZE / 2, width(), y - SNAP_SIZE / 2);
1387 -                                       pbuf.drawRect(x-1,y-1,2,2);
1388 -                               }
1389 -                       }
1390 -               }
1391 -               if (_isShowGuide) {
1392 -                       pbuf.setPen(QPen(cyan, 1, DashLine));
1393 -                       if (AS_HORIZONTAL == _asMode || AS_BOTH == _asMode) {
1394 -                               if (0 != _origin.x() || _isUseAllQuadrant) {
1395 -                                       pbuf.drawLine(width() / _margin, 0, width() / _margin, height());
1396 -                               }
1397 -                               pbuf.drawLine(width() * (_margin - 1) / _margin, 0, width() * (_margin - 1) / _margin, height());
1398 -                       }
1399 -
1400 -                       if (AS_VERTICAL == _asMode || AS_BOTH == _asMode) {
1401 -                               if (0 != _origin.y() || _isUseAllQuadrant) {
1402 -                                       pbuf.drawLine(0, height() / _margin, width(), height() / _margin);
1403 -                               }
1404 -                               pbuf.drawLine(0, height() * (_margin - 1) / _margin, width(), height() * (_margin - 1) / _margin);
1405 -                       }
1406 -               }
1407 -
1408 -               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1409 -                       FNPolygon* p = _draws.at(i);
1410 -                       if (r.intersects(p->boundingRect())) {
1411 -                               p->drawShape(pbuf);
1412 -                       }
1413 -               }
1414 -       } else {
1415 -               int w = _eraser_s;
1416 -               if (PENWIDTH_MAX / 2 < _pen.width()) {
1417 -                       w = _eraser_l;
1418 -               }
1419 -               FNPointList removes;
1420 -               for (uint i = 0; i < _tracks.count(); ++i) {
1421 -                       removes.append(_tracks.at(i));
1422 -               }
1423 -               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1424 -                       FNPolygon* p = _draws.at(i);
1425 -                       if (r.intersects(p->boundingRect())) {
1426 -                               bool f = false;
1427 -                               for (uint j = 0; j < _tracks.count(); ++j) {
1428 -                                       QPoint* pts = _tracks.at(j);
1429 -                                       QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w);
1430 -                                       for (uint k = 0; k < p->points().count(); ++k) {
1431 -                                               QPoint& pts2 = p->points().at(k);
1432 -                                               if (selected.contains(pts2)) {
1433 -                                                       f = true;
1434 -                                                       removes.remove(pts);
1435 -                                                       break;
1436 -                                               }
1437 -                                       }
1438 -                                       if (f) {
1439 -                                               break;
1440 -                                       }
1441 -                               }
1442 -                               p->drawShape(pbuf, f);
1443 -                       }
1444 -               }
1445 -               for (uint i = 0; i < removes.count(); ++i) {
1446 -                       _tracks.remove(removes.at(i));
1447 -               }
1448 -               /*
1449 -               if (_isDragging) {
1450 -                       pbuf.setPen(QPen(black, 1));
1451 -                       pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
1452 -               }
1453 -               */
1454 -       }
1455 -       pbuf.end();
1456 -       repaint();
1457 -}
1458 -
1459 -void FNCanvas::changeColor(QRgb c)
1460 -{
1461 -       _pen.setColor(QColor(c));
1462 -}
1463 -
1464 -void FNCanvas::undo()
1465 -{
1466 -       if (MODE_ERASE != _drawMode) {
1467 -               ++_disp_offset;
1468 -               if (_disp_offset > _draws.count()) {
1469 -                       _disp_offset = _draws.count();
1470 -               }
1471 -       } else {
1472 -               _draws = _undobuf;
1473 -               _marks.clear();
1474 -       }
1475 -       redraw();
1476 -}
1477 -
1478 -void FNCanvas::redo()
1479 -{
1480 -       if (MODE_ERASE != _drawMode) {
1481 -               if (0 < _disp_offset) {
1482 -                       --_disp_offset;
1483 -               }
1484 -       }
1485 -       redraw();
1486 -}
1487 -
1488 -void FNCanvas::clearList(FNPolygonList& list)
1489 -{
1490 -       list.setAutoDelete(true);
1491 -       list.clear();
1492 -       list.setAutoDelete(false);
1493 -}
1494 -
1495 -void FNCanvas::clear()
1496 -{
1497 -       _disp_offset = 0;
1498 -       clearList(_draws);
1499 -       _undobuf.clear();
1500 -       setOrigin(0, 0);
1501 -       redraw();
1502 -}
1503 -
1504 -void FNCanvas::viewChanged(bool flg)
1505 -{
1506 -       _tracks.clear();
1507 -       _viewMode = flg;
1508 -       if (_viewMode) {
1509 -               if (_isUseAllQuadrant) {
1510 -                       rebuild();
1511 -               }
1512 -               setOrigin(0, 0);
1513 -       }
1514 -       redraw();
1515 -}
1516 -
1517 -void FNCanvas::redobuf_flush()
1518 -{
1519 -       for (uint i = 0; i < _disp_offset; ++i) {
1520 -               FNPolygon* p = _draws.last();
1521 -               _draws.remove(p);
1522 -               delete p;
1523 -       }
1524 -       _disp_offset = 0;
1525 -}
1526 -
1527 -void FNCanvas::modeChanged(int mode)
1528 -{
1529 -       _tracks.clear();
1530 -       _drawMode = mode;
1531 -       redobuf_flush();
1532 -       if (MODE_ERASE == _drawMode) {
1533 -               _marks.clear();
1534 -               _undobuf = _draws;
1535 -       } else {
1536 -               if (_draws.count() != _undobuf.count()) {
1537 -                       for (uint i = 0; i < _marks.count(); ++i) {
1538 -                               FNPolygon* p = _marks.at(i);
1539 -                               _draws.remove(p);
1540 -                       }
1541 -                       clearList(_marks);
1542 -               }
1543 -       }
1544 -       redraw();
1545 -}
1546 -
1547 -QRect FNCanvas::getMatrix(const QRect& r) const
1548 -{
1549 -       int ox = _origin.x();
1550 -       int oy = _origin.y();
1551 -       const int wide = 100;
1552 -
1553 -       int left = r.left() + ox;
1554 -       int top = r.top() + oy;
1555 -       int right = r.right() + ox;
1556 -       int bottom = r.bottom() + oy;
1557 -       
1558 -       left = (int)(left / wide) * wide;
1559 -       top = (int)(top / wide) * wide;
1560 -       right = (right % wide == 0 && left != right) ? right : (int)((right + wide) / wide) * wide;
1561 -       bottom = (bottom % wide == 0 && top != bottom) ? bottom : (int)((bottom + wide) / wide) * wide;
1562 -       
1563 -       return QRect(left - ox, top - oy, right - left, bottom - top);
1564 -}
1565 -
1566 -void FNCanvas::CR() 
1567 -{
1568 -       if (MODE_ERASE == _drawMode) {
1569 -               return;
1570 -       }
1571 -       if (_isHeadingEnables) {
1572 -               //last\82©\82ç\81A\8d\95û\8cü\82É\8cü\82¯\82Ä\92T\8dõ\82·\82é\81B
1573 -               QRect r = getMatrix(_draws.last()->boundingRect());
1574 -               bool isSearching = true;
1575 -               r.moveBy(-100, 0);
1576 -               while (isSearching) {
1577 -                       isSearching = false;
1578 -                       for (uint i = 0; i < _draws.count(); ++i) {
1579 -                               FNPolygon* p = _draws.at(i);
1580 -                               const QRect& r2 = p->boundingRect();
1581 -                               if (r.intersects(r2)) {
1582 -                                       if (r.left() + 100 > r2.left()) {
1583 -                                               r = getMatrix(r2);
1584 -                                               r.moveBy(-100, 0);
1585 -                                               isSearching = true;
1586 -                                               break;
1587 -                                       }
1588 -                               }
1589 -                       }
1590 -               }
1591 -               r.moveBy(100, 0);
1592 -               //last\82ª\89æ\96Ê\82Ì4/5\88È\89º\82È\82ç\82Î\81A\83X\83N\83\8d\81[\83\8b\83A\83b\83v\82·\82é\81B
1593 -               //\82»\82¤\82Å\82È\82¯\82ê\82Î\81A\83w\83b\83f\83B\83\93\83O\82Ì\82Ý\81B
1594 -               if (_last.y() > height() * 4 / 5) {
1595 -                       setOrigin(_origin.x() + r.x(), _origin.y() + 50);
1596 -               } else {
1597 -                       setOrigin(_origin.x() + r.x(), _origin.y());
1598 -               }
1599 -               _isHeadingEnables = false;
1600 -       } else {
1601 -               //last\82Ì\8eü\88Í\82É\89½\82à\96³\82¢\8fê\8d\87\82Í\81A\8fc\82É\83X\83N\83\8d\81[\83\8b\82·\82é\81B
1602 -               setOrigin(_origin.x(), _origin.y() + 50);
1603 -       }
1604 -}
1605 -
1606 -void FNCanvas::erase()
1607 -{
1608 -       if (MODE_ERASE != _drawMode) {
1609 -               return;
1610 -       }
1611 -       FNPolygonList temp;
1612 -       int w = _eraser_s;
1613 -       if (PENWIDTH_MAX / 2 < _pen.width()) {
1614 -               w = _eraser_l;
1615 -       }
1616 -       QRect r = QRect(0, 0, width(), height());
1617 -       for (uint i = 0; i < _draws.count(); ++i) {
1618 -               FNPolygon* p = _draws.at(i);
1619 -               bool f = false;
1620 -               if (r.intersects(p->boundingRect())) {
1621 -                       for (uint j = 0; j < _tracks.count(); ++j) {
1622 -                               QPoint* pts = _tracks.at(j);
1623 -                               QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w);
1624 -                               for (uint k = 0; k < p->points().count(); ++k) {
1625 -                                       QPoint& pts2 = p->points().at(k);
1626 -                                       if (selected.contains(pts2)) {
1627 -                                               temp.append(p);
1628 -                                               f = true;
1629 -                                               break;
1630 -                                       }
1631 -                               }
1632 -                               if (f) {
1633 -                                       break;
1634 -                               }
1635 -                       }
1636 -               }
1637 -       }
1638 -       for (uint i = 0; i < temp.count(); ++i) {
1639 -               _draws.remove(temp.at(i));
1640 -               _marks.append(temp.at(i));
1641 -       }
1642 -       _tracks.clear();
1643 -       redraw();
1644 -}
1645 -
1646 -void FNCanvas::setPensize(int sz)
1647 -{
1648 -       _pen.setWidth(sz);
1649 -}
1650 -
1651 -bool FNCanvas::exportPNG(const QFileInfo& info, QPixmap& buf)
1652 -{
1653 -       if (0 == info.fileName().length()) {
1654 -               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
1655 -               return false;
1656 -       }
1657 -       if (info.extension(false) != "png") {
1658 -               QMessageBox::warning(0,"FreeNoteQt", "extension '.png' expected.");
1659 -               return false;
1660 -       }
1661 -
1662 -       bool ret = buf.save(info.absFilePath(), "PNG");
1663 -       if (ret) {
1664 -               FNMessageBox::information(0,"FreeNoteQt", "export PNG complete.");
1665 -       } else {
1666 -               QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
1667 -       }
1668 -       return ret;
1669 -}
1670 -
1671 -QString FNCanvas::mkPDFscript(FNPolygon* elm)
1672 -{
1673 -       QString s ="";
1674 -       char buf[1024];
1675 -
1676 -       float r = (float)elm->pen().color().red() / 255.0f;
1677 -       float g = (float)elm->pen().color().green() / 255.0f;
1678 -       float b = (float)elm->pen().color().blue() / 255.0f;
1679 -       s += "q\n";
1680 -       sprintf(buf, "%f %f %f RG\n", r, g, b);
1681 -       s += buf;
1682 -       QPointArray points = elm->points().copy();
1683 -       points.translate(_origin.x(), _origin.y());
1684 -       if (elm->type() == FN_BEZIER) {
1685 -               sprintf(buf, "%d %d m\n", points[0].x(), points[0].y());
1686 -               s += buf;
1687 -               for (uint j = 1; j < points.count(); j += 3) {
1688 -                       sprintf(buf, "%d %d %d %d %d %d c\n",
1689 -                               points[j].x(), points[j].y(),
1690 -                               points[j + 1].x(), points[j + 1].y(),
1691 -                               points[j + 2].x(), points[j + 2].y()
1692 -                               );
1693 -                       s += buf;
1694 -               }
1695 -       } else if (elm->type() == FN_ELLIPSE) {
1696 -               int x = points[0].x();
1697 -               int y = points[0].y();
1698 -               int ex = points[1].x();
1699 -               int ey = points[1].y();
1700 -               int w = ex - x;
1701 -               int h = ey - y;
1702 -               int cx = x + w/2;
1703 -               int cy = y;
1704 -               int x1 = x + 3*w/4;
1705 -               int y1 = y;
1706 -               int x2 = x + w;
1707 -               int y2 = y + h/4;
1708 -               int x3 = x + w;
1709 -               int y3 = y + h/2;
1710 -               
1711 -               sprintf(buf, "%d %d m\n%d %d %d %d %d %d c\n", cx, cy, x1, y1, x2, y2, x3, y3);
1712 -               s += buf;
1713 -               x1 = x + w;
1714 -               y1 = y + 3 * h / 4;
1715 -               x2 = x + 3 * w / 4;
1716 -               y2 = y + h;
1717 -               x3 = x + w/2;
1718 -               y3 = y + h;
1719 -               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
1720 -               s += buf;
1721 -
1722 -               x1 = x + w / 4;
1723 -               y1 = y + h;
1724 -               x2 = x;
1725 -               y2 = y + 3 * h / 4;
1726 -               x3 = x;
1727 -               y3 = y + h / 2;
1728 -               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
1729 -               s += buf;
1730 -               x1 = x;
1731 -               y1 = y + h / 4;
1732 -               x2 = x + w / 4;
1733 -               y2 = y;
1734 -               x3 = x + w / 2;
1735 -               y3 = y;
1736 -               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
1737 -               s += buf;
1738 -       } else {
1739 -               sprintf(buf, "%d %d m\n", points[0].x(), points[0].y());
1740 -               s += buf;
1741 -               for (uint j = 1; j < points.count(); ++j) {
1742 -                       sprintf(buf, "%d %d l\n", points[j].x(), points[j].y());
1743 -                       s += buf;
1744 -               }
1745 -       }
1746 -       sprintf(buf, "%d w\n", elm->pen().width());
1747 -       s += buf;
1748 -       s += "S\n";
1749 -       s += "Q\n";
1750 -       return s;
1751 -}
1752 -
1753 -bool FNCanvas::exportPDF(const QFileInfo& info)
1754 -{
1755 -       if (0 == info.fileName().length()) {
1756 -               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
1757 -               return false;
1758 -       }
1759 -       if (info.extension(false) != "pdf") {
1760 -               QMessageBox::warning(0,"FreeNoteQt", "extension '.pdf' expected.");
1761 -               return false;
1762 -       }
1763 -
1764 -       FILE* fp = NULL;
1765 -       if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
1766 -               QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
1767 -               return false;
1768 -       }
1769 -
1770 -       QPoint o = getTopLeft();
1771 -       rebuild();
1772 -       int wx = 595;
1773 -       int wy = 842;
1774 -       char buf[1024];
1775 -       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1776 -               FNPolygon* p = _draws.at(i);
1777 -               QRect r = p->boundingRect();
1778 -               r.moveBy(_origin.x(), _origin.y());
1779 -               if (wx < r.right()) {
1780 -                       wx =r.right();
1781 -               }
1782 -               if (wy < r.bottom()) {
1783 -                       wy = r.bottom();
1784 -               }
1785 -       }
1786 -
1787 -       int len = 0;
1788 -       
1789 -       sprintf(buf, "1 0 0 -1 0 %d cm\n", wy);
1790 -       QString cm = buf;
1791 -       len += cm.length();
1792 -
1793 -       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1794 -               QString s = mkPDFscript(_draws.at(i));
1795 -               len += s.length();
1796 -       }
1797 -
1798 -       QString header = "";
1799 -       header += "%PDF-1.3\n";
1800 -       header += "1 0 obj\n";
1801 -       header += "<<\n";
1802 -       header += "/Type /Page\n";
1803 -       header += "/Parent 3 0 R\n";
1804 -       header += "/Resources\n";
1805 -       header += "<<\n";
1806 -       header += "/ProcSet [ /PDF ]\n";
1807 -       header += ">>\n";
1808 -       sprintf(buf, "/MediaBox [ 0 0 %010d %010d ]\n", wx, wy);
1809 -       header += buf;
1810 -       header += "/Contents 4 0 R\n";
1811 -       header += ">>\n";
1812 -       header += "endobj\n";
1813 -       header += "2 0 obj\n";
1814 -       header += "<<\n";
1815 -       header += "/Type /Catalog\n";
1816 -       header += "/Pages 3 0 R\n";
1817 -       header += "/PageLayout /OneColumn\n";
1818 -       header += "/OpenAction [1 0 R /XYZ null null 1 ]\n";
1819 -       header += ">>\n";
1820 -       header += "endobj\n";
1821 -       header += "3 0 obj\n";
1822 -       header += "<<\n";
1823 -       header += "/Type /Pages\n";
1824 -       header += "/Kids [ 1 0 R ]\n";
1825 -       header += "/Count 1\n";
1826 -       header += ">>\n";
1827 -       header += "endobj\n";
1828 -       header += "4 0 obj\n";
1829 -       sprintf(buf, "<< /Length %010d >>\n", len);
1830 -       header += buf;
1831 -       header += "stream\n";
1832 -
1833 -       QString footer = "";
1834 -       footer += "xref\n";
1835 -       footer += "0 5\n";
1836 -       footer += "0000000000 65535 f \n";
1837 -       footer += "0000000009 00000 n \n";
1838 -       footer += "0000000147 00000 n \n";
1839 -       footer += "0000000257 00000 n \n";
1840 -       footer += "0000000316 00000 n \n";
1841 -       footer += "trailer\n";
1842 -       footer += "<<\n";
1843 -       footer += "/Size 5\n";
1844 -       footer += "/Root 2 0 R\n";
1845 -       footer += ">>\n";
1846 -       footer += "startxref\n";
1847 -
1848 -       len = cm.length();
1849 -       len += header.length();
1850 -       fputs(header, fp);
1851 -       fputs(cm, fp);
1852 -
1853 -       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1854 -               QString s = mkPDFscript(_draws.at(i));
1855 -               len += s.length();
1856 -               fputs(s, fp);
1857 -       }
1858 -       QString streamfooter = "endstream\nendobj\n";
1859 -       len += streamfooter.length();
1860 -       fputs(streamfooter, fp);
1861 -
1862 -       fputs(footer, fp);
1863 -       sprintf(buf, "%d\n", len);
1864 -       fputs(buf, fp);
1865 -       fputs("%%EOF\n", fp);
1866 -       fclose(fp);
1867 -       if (_isUseAllQuadrant) {
1868 -               setOrigin(-o.x(), -o.y());
1869 -       }
1870 -       FNMessageBox::information(0,"FreeNoteQt", "export PDF complete.");
1871 -       return true;
1872 -}
1873 -
1874 -bool FNCanvas::save(const QFileInfo& info)
1875 -{
1876 -       if (0 == info.fileName().length()) {
1877 -               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
1878 -               return false;
1879 -       }
1880 -       if (info.extension(false) != "free") {
1881 -               QMessageBox::warning(0,"FreeNoteQt", "extension '.free' expected.");
1882 -               return false;
1883 -       }
1884 -       FILE* fp = NULL;
1885 -       if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
1886 -               QMessageBox::warning(0,"FreeNoteQt", "could not save file.");
1887 -               return false;
1888 -       }
1889 -       QPoint o = getTopLeft();
1890 -       rebuild();
1891 -       fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
1892 -       fputs("<freenote version=\"2.0\">\n", fp);
1893 -       char buf[1024];
1894 -       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
1895 -               FNPolygon p(*_draws.at(i));
1896 -               p.translate(_origin.x(), _origin.y());
1897 -               if (p.type() == FN_BEZIER) {
1898 -                       sprintf(buf, "\t<bz color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
1899 -               } else if (p.type() == FN_ELLIPSE) {
1900 -                       sprintf(buf, "\t<el color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
1901 -               } else {
1902 -                       sprintf(buf, "\t<po color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
1903 -               }
1904 -               fputs(buf, fp);
1905 -               QPointArray& points = p.points();
1906 -               for (uint j = 0; j < points.count(); ++j) {
1907 -                       QPoint point = points.point(j);
1908 -                       sprintf(buf, "\t\t<p x=\"%d\" y=\"%d\"/>\n", point.x(), point.y());
1909 -                       fputs(buf, fp);
1910 -               }
1911 -               if (p.type() == FN_BEZIER) {
1912 -                       fputs("\t</bz>\n", fp);
1913 -               } else if (p.type() == FN_ELLIPSE) {
1914 -                       fputs("\t</el>\n", fp);
1915 -               } else {
1916 -                       fputs("\t</po>\n", fp);
1917 -               }
1918 -       }
1919 -       fputs("</freenote>\n", fp);
1920 -       fclose(fp);
1921 -       if (_isUseAllQuadrant) {
1922 -               setOrigin(-o.x(), -o.y());
1923 -       }
1924 -       FNMessageBox::information(0, "FreeNoteQt", "save complete.");
1925 -       return true;
1926 -}
1927 -
1928 -bool FNCanvas::load(const QFileInfo& info)
1929 -{
1930 -       if (0 == info.fileName().length()) {
1931 -               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
1932 -               return false;
1933 -       }
1934 -       if (!info.exists()) {
1935 -               QMessageBox::warning(0,"FreeNoteQt", "file not exists.");
1936 -               return false;
1937 -       }
1938 -       FILE* fp = NULL;
1939 -       if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) {
1940 -               QMessageBox::warning(0,"FreeNoteQt", "could not open file.");
1941 -               return false;
1942 -       }
1943 -       clear();
1944 -
1945 -       QString line;
1946 -       FNPointList points;
1947 -       points.setAutoDelete(true);
1948 -       int c;
1949 -       int w;
1950 -       QPen pen(Qt::black, 1);
1951 -       FNPolygon* polygon;
1952 -       
1953 -       char rdbuf[1024];
1954 -       char buf[1024];
1955 -       QString type = "";
1956 -       while (!feof(fp)) {
1957 -               fgets(rdbuf, sizeof(rdbuf), fp);
1958 -               line = rdbuf;
1959 -               if (-1 != line.find("<fnpolygon ") ||
1960 -                       -1 != line.find("<po ") ||
1961 -                       -1 != line.find("<bz ") ||
1962 -                       -1 != line.find("<el ")
1963 -               ) {
1964 -                       if (-1 != line.find("<el ")) {
1965 -                               type = "Ellipse";
1966 -                       } else if (-1 != line.find("<bz ")) {
1967 -                               type = "Bezier";
1968 -                       } else {
1969 -                               type = "Polygon";
1970 -                       }
1971 -                       points.clear();
1972 -                       int st = line.find("color") + 7;
1973 -                       int ed = line.find("\"", st);
1974 -                       strcpy(buf, line.mid(st, ed - st).utf8());
1975 -                       sscanf(buf, "%x", &c);
1976 -                       st = line.find("width") + 7;
1977 -                       ed = line.find("\"", st);
1978 -                       strcpy(buf, line.mid(st, ed - st).utf8());
1979 -                       sscanf(buf, "%d", &w);
1980 -               } else if (-1 != line.find("<point ") ||
1981 -                       -1 != line.find("<p ")
1982 -                       ) {
1983 -                       int st = line.find("x=") + 3;
1984 -                       int ed = line.find("\"", st);
1985 -                       strcpy(buf, line.mid(st, ed - st).utf8());
1986 -                       int x;
1987 -                       sscanf(buf, "%d", &x);
1988 -
1989 -                       st = line.find("y=") + 3;
1990 -                       ed = line.find("\"", st);
1991 -                       strcpy(buf, line.mid(st, ed - st).utf8());
1992 -                       int y;
1993 -                       sscanf(buf, "%d", &y);
1994 -                       points.append(createPts(x, y)); //\83o\83O\91Î\8dô
1995 -               } else if (-1 != line.find("</fnpolygon") || 
1996 -                       -1 != line.find("</bz") ||
1997 -                       -1 != line.find("</el") ||
1998 -                       -1 != line.find("</po")) {
1999 -                       pen.setColor((QRgb)c);
2000 -                       pen.setWidth(w);
2001 -                       if (type == "Bezier") {
2002 -                               _draws.append(polygon = createBezier(pen)); //\83o\83O\91Î\8dô
2003 -                       } else if (type == "Ellipse") {
2004 -                               _draws.append(polygon = createEllipse(pen)); //\83o\83O\91Î\8dô
2005 -                       } else {
2006 -                               _draws.append(polygon = createPolygon(pen)); //\83o\83O\91Î\8dô
2007 -                       }
2008 -                       polygon->setPoints(points);
2009 -                       points.clear();
2010 -               }
2011 -       }
2012 -       fclose(fp);
2013 -       int x = 0;
2014 -       int y = 0;
2015 -       for (uint i = 0; i < _draws.count(); ++i) {
2016 -               if (y > _draws.at(i)->boundingRect().top()) {
2017 -                       y = _draws.at(i)->boundingRect().top();
2018 -               }
2019 -               if (x > _draws.at(i)->boundingRect().left()) {
2020 -                       x = _draws.at(i)->boundingRect().left();
2021 -               }
2022 -       }
2023 -       for (uint i = 0; i < _draws.count(); ++i) {
2024 -               _draws.at(i)->translate(-x, -y);
2025 -       }
2026 -       redraw();
2027 -       FNMessageBox::information(0,"FreeNoteQt", "load complete.");
2028 -
2029 -       return true;
2030 -}
2031 -
2032 -FNPolygon* FNCanvas::createPolygon(QPen& pen)
2033 -{
2034 -       return new FNPolygon(pen);
2035 -}
2036 -
2037 -FNPolygon* FNCanvas::createBezier(QPen& pen)
2038 -{
2039 -       return new FNBezier(pen);
2040 -}
2041 -
2042 -
2043 -FNPolygon* FNCanvas::createEllipse(QPen& pen)
2044 -{
2045 -       return new FNEllipse(pen);
2046 -}
2047 -
2048 -QPoint* FNCanvas::createPts(int x, int y) 
2049 -{
2050 -       return new QPoint(x, y);
2051 -}
2052 -
2053 -void FNCanvas::setGuide(bool f)
2054 -{
2055 -       _isShowGuide = f;
2056 -       redraw();
2057 -}
2058 +/*  FreeNote for Sharp SLA300, B500, C7x0 Linux PDA
2059 +       Copyright (C) 2003 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
2060 +
2061 +    This program is free software; you can redistribute it and/or modify
2062 +    it under the terms of the GNU General Public License as published by
2063 +    the Free Software Foundation; either version 2 of the License, or
2064 +    (at your option) any later version.
2065 +
2066 +    This program is distributed in the hope that it will be useful,
2067 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
2068 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2069 +    GNU General Public License for more details.
2070 +
2071 +    You should have received a copy of the GNU General Public License
2072 +    along with this program; if not, write to the Free Software
2073 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2074 +*/
2075 +/*
2076 +2003/12/23 ver 1.6.1
2077 +\81E\95Û\91\8fî\95ñ\82Ì\83T\83C\83Y\8fk\8f¬
2078 +
2079 +2003/12/16-19 ver 1.5.5pre
2080 +\81E\83y\83\93\83T\83C\83Y\82Ì\92Ç\89Á(1-8)
2081 +\81E\83A\83\93\83h\83D\81E\83\8a\83h\83D\82Ì\8eÀ\91\95
2082 +
2083 +2003/12/14 ver 1.5.4pre
2084 +\81E\83y\83\93\83T\83C\83Y\82ð\91I\91ð\89Â\94\\82É\81B
2085 +
2086 +2003/12/05 ver 1.5.3Apre
2087 +\81E\83O\83\8a\83b\83h\82Ì\90F\82ð\8fC\90³
2088 +
2089 +2003/12/04 ver 1.5.3pre
2090 +\81E\83O\83\8a\83b\83h\82Ì\95`\89æ\82ð\88ê\95\94\8fC\90³
2091 +
2092 +2003/11/10 ver 1.5.1pre
2093 +\81E\8bÈ\90ü\90®\8c`\83\82\81[\83h\92Ç\89Á
2094 +
2095 +2003/11/09 ver 1.5.0pre
2096 +\81E\8e©\93®\90®\8c`\83\82\81[\83h\92Ç\89Á
2097 +
2098 +2003/09/03 ver 1.3.4pre
2099 +\81EUse all quadrant OFF\8e\9e\82É\95\\8e¦\88Ê\92u\82ª\83\8a\83Z\83b\83g\82³\82ê\82é\8fê\8d\87\82ª\82 \82é\83o\83O\91Î\89\9e\81B
2100 +
2101 +2003/09/01-03 ver 1.3.3pre
2102 +\81E\83X\83N\83\8d\81[\83\8b\82Ì\89ü\97Ç
2103 +\81EUse all quadrant(\91S\8fÛ\8cÀ\82ð\8eg\97p\82·\82é)\83\81\83j\83\85\81[\82ð\92Ç\89Á
2104 +
2105 +2003/08/31 FreeNote 1.3.2pre
2106 +\81E\91S\95û\8cü\83X\83N\83\8d\81[\83\8b
2107 +
2108 +2003/08/23 FreeNote 1.3.0pre
2109 +\81ECR\93®\8dì\82Ì\8fC\90³
2110 +
2111 +2003/08/15 FreeNote 1.2.1\82ð\8cö\8aJ
2112 +\81E\95Û\91\8e\9e\82Ì\83o\83O\8fC\90³
2113 +\81E\8a®\97¹\83_\83C\83A\83\8d\83O\82Ì\8e©\93®\8fÁ\8b\8e
2114 +\81EPNG\83t\83@\83C\83\8b\82Ö\82Ì\8fo\97Í
2115 +
2116 +2003/08/15 FreeNote 1.2\82ð\8cö\8aJ
2117 +\81E\83I\83v\83V\83\87\83\93\92Ç\89Á
2118 +\81E\83X\83N\83\8d\81[\83\8b\83K\83C\83h
2119 +\81EFree\83t\83@\83C\83\8b\8aÖ\98A\95t\82¯
2120 +\81E\83A\83C\83R\83\93\82Ì\95Ï\8dX
2121 +
2122 +2003/08/05 FreeNote 1.1.1pre\82ð\8cö\8aJ
2123 +\81E\8d\82\91¬\8bN\93®\8e\9e\82É\95Â\82\82½\8fó\91Ô\82ð\95Û\8e\9d
2124 +\81E\95`\89æ\83\82\81[\83h\90Ø\91Ö\82¦\8e\9e\82É\8fÁ\82µ\83S\83\80\95\\8e¦
2125 +\81E\95Û\91\8e\9e\8aÔ\92Z\8fk
2126 +\81EView\83\82\81[\83h\82Ì\8b\93\93®\82ð\95Ï\8dX
2127 +\81E\83\81\83j\83\85\81[\82Ì\8c©\82½\96Ú\82ð\95Ï\8dX
2128 +*/
2129 +#include "fncanvas.h"
2130 +#include <stdio.h>
2131 +#include <qfile.h>
2132 +#include <qmessagebox.h>
2133 +#include <qtextstream.h>
2134 +#include <qpen.h>
2135 +#include <qcolor.h>
2136 +#include <qpoint.h>
2137 +#include <qthread.h>
2138 +#include <qimage.h>
2139 +#include <math.h>
2140 +#include <stdlib.h> // abs
2141 +#include "fnmessagebox.h"
2142 +#include "fmtengine.h"
2143 +
2144 +int snap(int v) {
2145 +       int tv = abs(v);
2146 +       tv = ((int)(tv + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
2147 +       if (0 > v) {
2148 +               return -tv;
2149 +       } else {
2150 +               return tv;
2151 +       }
2152 +}
2153 +
2154 +FNCanvas::FNCanvas(QWidget* parent, const char* name, WFlags f )
2155 +       :QWidget(parent, name, f),
2156 +       _pen(black, 1, SolidLine, RoundCap, RoundJoin), 
2157 +       _asMode(AS_NONE),
2158 +       _drawMode(MODE_DRAW),
2159 +       _disp_offset(0),
2160 +       _eraser_l(50),
2161 +       _eraser_s(10),
2162 +       _h_step(100),
2163 +       _v_step(100),
2164 +       _margin(5),
2165 +       _scrollTiming(800),
2166 +       _viewMode(false),
2167 +       _isWaiting(false),
2168 +       _isDragging(false),
2169 +       _isHeadingEnables(false),
2170 +       _isShowGuide(false),
2171 +       _isUseAllQuadrant(false),
2172 +       _scale_x(1.0),
2173 +       _scale_y(1.0)
2174 +{
2175 +       _tracks.setAutoDelete(true);
2176 +       this->setBackgroundMode(NoBackground);
2177 +       _timer = new QTimer(this);
2178 +       connect(_timer, SIGNAL(timeout()), this, SLOT(autoScroll()));
2179 +}
2180 +
2181 +FNCanvas::~FNCanvas()
2182 +{
2183 +       _timer->stop();
2184 +       delete _timer;
2185 +
2186 +       _tracks.clear();
2187 +       clearList(_draws);
2188 +}
2189 +
2190 +void FNCanvas::setScrollTiming(int v)
2191 +{
2192 +       _scrollTiming = v;
2193 +}
2194 +
2195 +
2196 +void FNCanvas::setVStep(int v)
2197 +{
2198 +       _v_step = v;
2199 +}
2200 +
2201 +void FNCanvas::setHStep(int v)
2202 +{
2203 +       _h_step = v;
2204 +}
2205 +
2206 +void FNCanvas::setSEraser(int v)
2207 +{
2208 +       _eraser_s = v;
2209 +}
2210 +
2211 +void FNCanvas::setLEraser(int v)
2212 +{
2213 +       _eraser_l = v;
2214 +}
2215 +
2216 +
2217 +void FNCanvas::setMargin(int v)
2218 +{
2219 +       if (v < 3) {
2220 +               v = 3;
2221 +       }
2222 +       _margin = v;
2223 +}
2224 +
2225 +void FNCanvas::setScrollMode(int as)
2226 +{
2227 +       _asMode = as;
2228 +       redraw();
2229 +}
2230 +
2231 +void FNCanvas::autoScroll()
2232 +{
2233 +       if (AS_NONE == _asMode) {
2234 +               if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_SMOOTH == _drawMode) {
2235 +                       setOrigin(_origin.x(), _origin.y());
2236 +               }
2237 +               return;
2238 +       }
2239 +       bool tmp = _isHeadingEnables;
2240 +       int dx = 0;
2241 +       int dy = 0;
2242 +       if (AS_BOTH == _asMode || AS_HORIZONTAL == _asMode) {
2243 +               if (_last.x() > width() * (_margin - 1) / _margin) {
2244 +                       dx = _h_step;
2245 +               } else if (_last.x() < width() / _margin) {
2246 +                       dx = -_h_step;
2247 +               }
2248 +       }
2249 +       if (AS_BOTH == _asMode || AS_VERTICAL == _asMode) {
2250 +               if (_last.y() > height() * (_margin - 1) / _margin) {
2251 +                       dy = _v_step;
2252 +               } else if (_last.y() < height() / _margin) {
2253 +                       dy = -_v_step;
2254 +               }
2255 +       }
2256 +       setOrigin(_origin.x() + dx, _origin.y() + dy);
2257 +       _isHeadingEnables = tmp;
2258 +}
2259 +
2260 +void FNCanvas::mousePressEvent(QMouseEvent* evt)
2261 +{
2262 +       setFocus();
2263 +       _timer->stop();
2264 +       _tracks.clear();
2265 +       if (_viewMode) {
2266 +               _isWaiting = true;
2267 +               _viewMode = false;
2268 +               setOrigin((int)((evt->x()) / _scale_x) - width() / 2, (int)((evt->y()) / _scale_y) - height() / 2);
2269 +               redraw();
2270 +               emit resetViewMode();
2271 +       } else if (MODE_ERASE != _drawMode) {
2272 +               _last = evt->pos();
2273 +               _tracks.append(new QPoint(_last));
2274 +       } else {
2275 +               redraw();
2276 +               _last = evt->pos();
2277 +               _tracks.append(new QPoint(_last));
2278 +
2279 +               QPainter pbuf;
2280 +               QPainter pwin;
2281 +               pbuf.begin(&_buffer);
2282 +               pwin.begin(this);
2283 +
2284 +               int w = _eraser_s;
2285 +               if (PENWIDTH_MAX / 2 < _pen.width()) {
2286 +                       w = _eraser_l;
2287 +               }
2288 +               pbuf.setRasterOp(XorROP);
2289 +               pbuf.setPen(QPen(white, 1));
2290 +               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2291 +
2292 +               pwin.setRasterOp(XorROP);
2293 +               pwin.setPen(QPen(white, 1));
2294 +               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2295 +
2296 +               pbuf.end();
2297 +               pwin.end();
2298 +       }
2299 +       _isDragging = true;
2300 +}
2301 +
2302 +void FNCanvas::mouseMoveEvent(QMouseEvent* evt)
2303 +{
2304 +       if (_isWaiting) {
2305 +               return;
2306 +       }
2307 +       if (MODE_ERASE != _drawMode) {
2308 +               QPainter pwin;
2309 +               QPainter pbuf;
2310 +               
2311 +               pwin.begin(this);
2312 +               pbuf.begin(&_buffer);
2313 +               
2314 +               pwin.setPen(_pen);
2315 +               pbuf.setPen(_pen);
2316 +               
2317 +               pwin.drawLine(_last, evt->pos());
2318 +               pbuf.drawLine(_last, evt->pos());
2319 +               
2320 +               pwin.end();
2321 +               pbuf.end();
2322 +               _last = evt->pos();
2323 +               _tracks.append(new QPoint(_last));
2324 +       } else {
2325 +               //redraw();
2326 +               if (_last.x() == -1) {
2327 +                       return;
2328 +               }
2329 +               QPainter pbuf;
2330 +               QPainter pwin;
2331 +               
2332 +               pbuf.begin(&_buffer);
2333 +               pwin.begin(this);
2334 +
2335 +               int w = _eraser_s;
2336 +               if (PENWIDTH_MAX / 2 < _pen.width()) {
2337 +                       w = _eraser_l;
2338 +               }
2339 +               pbuf.setRasterOp(XorROP);
2340 +               pwin.setRasterOp(XorROP);
2341 +               pbuf.setPen(QPen(white, 1));
2342 +               pwin.setPen(QPen(white, 1));
2343 +               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2344 +               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2345 +
2346 +               _tracks.append(new QPoint(evt->pos()));
2347 +               _last = evt->pos();
2348 +
2349 +               pbuf.setRasterOp(CopyROP);
2350 +               pwin.setRasterOp(CopyROP);
2351 +               QRect r = QRect(0, 0, width(), height());
2352 +               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
2353 +                       FNPolygon* p = _draws.at(i);
2354 +                       if (r.intersects(p->boundingRect())) {
2355 +                               bool f = false;
2356 +                               QRect selected(_last.x() - w / 2, _last.y() - w / 2, w, w);
2357 +                               for (uint j = 0; j < p->points().count(); ++j) {
2358 +                                       QPoint& pts = p->points().at(j);
2359 +                                       if (selected.contains(pts)) {
2360 +                                               f = true;
2361 +                                               break;
2362 +                                       }
2363 +                               }
2364 +                               if (f) {
2365 +                                       p->drawShape(pbuf, f);
2366 +                                       p->drawShape(pwin, f);
2367 +                               }
2368 +                       }
2369 +               }
2370 +               pbuf.setRasterOp(XorROP);
2371 +               pwin.setRasterOp(XorROP);
2372 +               pbuf.setPen(QPen(white, 1));
2373 +               pwin.setPen(QPen(white, 1));
2374 +               pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2375 +               pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2376 +               pbuf.end();
2377 +               pwin.end();
2378 +       }
2379 +}
2380 +
2381 +void FNCanvas::mouseReleaseEvent(QMouseEvent* evt)
2382 +{
2383 +       _isDragging = false;
2384 +       if (_isWaiting) {
2385 +               _isWaiting = false;
2386 +               return;
2387 +       }
2388 +       _last = evt->pos();
2389 +       if (MODE_ERASE != _drawMode) {
2390 +               if (1 < _tracks.count()) {
2391 +                       FNPolygon* p = NULL;
2392 +                       if (MODE_FORMAT == _drawMode) {
2393 +                               p = new FNPolygon(_pen);
2394 +                               _tracks = AutoFormat(_tracks);
2395 +                       } else if (MODE_CURVE == _drawMode) {
2396 +                               QPoint sp = SnapPoint(*_tracks.at(0));
2397 +                               QPoint ep = SnapPoint(*_tracks.at(_tracks.count()-1));
2398 +                               _tracks = AutoCurve(_tracks);
2399 +                               if (sp == ep) {
2400 +                                       p = new FNEllipse(_pen);
2401 +                               } else if (2 < _tracks.count()) {
2402 +                                       p = new FNBezier(_pen);
2403 +                               } else {
2404 +                                       p = new FNPolygon(_pen);
2405 +                               }
2406 +                       } else if (MODE_SMOOTH == _drawMode) {
2407 +                               _tracks = Smoothing(_tracks);
2408 +                               if (2 < _tracks.count()) {
2409 +                                       p = new FNBezier(_pen);
2410 +                               } else {
2411 +                                       p = new FNPolygon(_pen);
2412 +                               }
2413 +                       } else {
2414 +                               _tracks = Reduce(_tracks);
2415 +                               p = new FNPolygon(_pen);
2416 +                       }
2417 +                       if (1 < _tracks.count()) {
2418 +                               p->setPoints(_tracks);
2419 +                               redobuf_flush();
2420 +                               _draws.append(p);
2421 +                       }
2422 +               }
2423 +               _tracks.clear();
2424 +               _isHeadingEnables = true;
2425 +               _timer->start(_scrollTiming, true);
2426 +       } else {
2427 +               _last = QPoint(-1, -1);
2428 +               _tracks.append(new QPoint(evt->pos()));
2429 +               redraw();
2430 +       }
2431 +}
2432 +
2433 +void FNCanvas::paintEvent(QPaintEvent* evt)
2434 +{
2435 +       bitBlt(this, 0, 0, &_buffer);
2436 +}
2437 +
2438 +void FNCanvas::resizeEvent(QResizeEvent* evt)
2439 +{
2440 +       QPixmap save(_buffer);
2441 +       _buffer.resize(evt->size());
2442 +       _buffer.fill(white);
2443 +       bitBlt(&_buffer, 0, 0, &save);
2444 +       redraw();
2445 +}
2446 +
2447 +void FNCanvas::setOrigin(QPoint& o)
2448 +{
2449 +       this->setOrigin(o.x(), o.y());
2450 +}
2451 +
2452 +QPoint FNCanvas::getTopLeft()
2453 +{
2454 +       if (0 == _draws.count() || !_isUseAllQuadrant) {
2455 +               return _origin;
2456 +       }
2457 +
2458 +       int dx = ((FNPolygon*)_draws.at(0))->boundingRect().x();
2459 +       int dy = ((FNPolygon*)_draws.at(0))->boundingRect().y();
2460 +       for (uint i = 1; i < _draws.count(); ++i) {
2461 +               FNPolygon* p = _draws.at(i);
2462 +               if (dx > p->boundingRect().x()) {
2463 +                       dx = p->boundingRect().x();
2464 +               }
2465 +               if (dy > p->boundingRect().y()) {
2466 +                       dy = p->boundingRect().y();
2467 +               }
2468 +       }
2469 +       return QPoint(snap(dx), snap(dy));
2470 +}
2471 +
2472 +
2473 +void FNCanvas::rebuild()
2474 +{
2475 +       if (0 == _draws.count() || !_isUseAllQuadrant) {
2476 +               return;
2477 +       }
2478 +
2479 +       QPoint d = getTopLeft();
2480 +       for (uint i = 0; i < _draws.count(); ++i) {
2481 +               FNPolygon* p = _draws.at(i);
2482 +               p->translate(-d.x(), -d.y());
2483 +       }
2484 +
2485 +       _origin = QPoint(0, 0);
2486 +}
2487 +
2488 +
2489 +void FNCanvas::setOrigin(int ox, int oy)
2490 +{
2491 +       ox = snap(ox);
2492 +       oy = snap(oy);
2493 +       _isHeadingEnables = false;
2494 +       _timer->stop();
2495 +
2496 +
2497 +       int dx = 0;
2498 +       int dy = 0;
2499 +       if (!_isUseAllQuadrant) {
2500 +               if (0 > ox) {
2501 +                       ox = 0;
2502 +               }
2503 +               if (0 > oy) {
2504 +                       oy = 0;
2505 +               }
2506 +               dx = _origin.x() - ox;
2507 +               dy = _origin.y() - oy;
2508 +       } else {
2509 +               dx = _origin.x() - ox;
2510 +               dy = _origin.y() - oy;
2511 +               if (0 > ox) {
2512 +                       ox = 0;
2513 +               }
2514 +               if (0 > oy) {
2515 +                       oy = 0;
2516 +               }
2517 +       }
2518 +       for (uint i = 0; i < _tracks.count(); ++i) {
2519 +               QPoint* p = _tracks.at(i);
2520 +               p->setX(p->x() + dx);
2521 +               p->setY(p->y() + dy);
2522 +       }
2523 +
2524 +       for (uint i = 0; i < _draws.count(); ++i) {
2525 +               FNPolygon* p = _draws.at(i);
2526 +               p->translate(dx, dy);
2527 +       }
2528 +       _origin = QPoint(ox, oy);
2529 +       emit originChanged(ox, oy);
2530 +       redraw();
2531 +}
2532 +
2533 +void FNCanvas::redraw()
2534 +{
2535 +       if (!this->isVisible()) {
2536 +               return;
2537 +       }
2538 +       _buffer.fill(white);
2539 +       QPainter pbuf;
2540 +       QRect r = QRect(0, 0, width(), height());
2541 +       pbuf.begin(&_buffer);
2542 +       if (_viewMode) {
2543 +               float wx = 0;
2544 +               float wy = 0;
2545 +               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
2546 +                       FNPolygon* p = _draws.at(i);
2547 +                       QRect r = p->boundingRect();
2548 +                       if (wx < r.right()) {
2549 +                               wx = r.right();
2550 +                       } 
2551 +                       if (wy < r.bottom()) {
2552 +                               wy = r.bottom();
2553 +                       }
2554 +               }
2555 +               wx += SNAP_SIZE;
2556 +               wy += SNAP_SIZE;
2557 +               wx = snap((int)wx);
2558 +               wy = snap((int)wy);
2559 +               wx = wx + _origin.x();
2560 +               wy = wy + _origin.y();
2561 +               _scale_x = (float)width() / wx;
2562 +               _scale_y = (float)height() / wy;
2563 +               if (1.0f < _scale_x) { 
2564 +                       _scale_x = 1.0f;
2565 +               }
2566 +               if (1.0f < _scale_y) {
2567 +                       _scale_y = 1.0f;
2568 +               }
2569 +               if (_scale_x > _scale_y) {
2570 +                       _scale_x = _scale_y;
2571 +               } else if (_scale_x < _scale_y) {
2572 +                       _scale_y = _scale_x;
2573 +               }
2574 +               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
2575 +                       FNPolygon* p = _draws.at(i);
2576 +                       FNPolygon* t = NULL;
2577 +                       if (p->type() == FN_BEZIER) {
2578 +                               t = new FNBezier(*(FNBezier*)p);
2579 +                       } else if (p->type() == FN_ELLIPSE) {
2580 +                               t = new FNEllipse(*(FNEllipse*)p);
2581 +                       } else {
2582 +                               t = new FNPolygon(*p);
2583 +                       }
2584 +                       t->translate(-_origin.x(), -_origin.y());
2585 +                       for (uint j = 0; j < t->points().count(); ++j) {
2586 +                               QPoint& pts = t->points().at(j);
2587 +                               int x = (int)(pts.x() * _scale_x);
2588 +                               int y = (int)(pts.y() * _scale_y);
2589 +                               pts.setX(x);
2590 +                               pts.setY(y);
2591 +                       }
2592 +                       double pensize = t->pen().width();
2593 +                       if (_scale_x > _scale_y) {
2594 +                               pensize = pensize * _scale_y;
2595 +                       } else {
2596 +                               pensize = pensize * _scale_x;
2597 +                       }
2598 +                       if (0 >= pensize) {
2599 +                               pensize = 1;
2600 +                       }
2601 +                       t->pen().setWidth(pensize);
2602 +                       t->drawShape(pbuf);
2603 +                       delete t;
2604 +               }
2605 +       } else if (MODE_ERASE != _drawMode) {
2606 +               if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode) {
2607 +                       QPen pen1(QColor(0, 240, 240), 1);
2608 +                       QPen pen2(QColor(0, 0, 0), 1);
2609 +                       pbuf.setPen(QPen(QColor(0, 240, 240), 1));
2610 +                       pbuf.setPen(pen1);
2611 +                       for (int x = 0; x < width() + SNAP_SIZE; x += SNAP_SIZE) {
2612 +                               pbuf.drawLine(x - SNAP_SIZE / 2, 0, x - SNAP_SIZE / 2, height());
2613 +                               for (int y = 0; y < height() + SNAP_SIZE; y += SNAP_SIZE) {
2614 +                                       pbuf.drawLine(0, y - SNAP_SIZE / 2, width(), y - SNAP_SIZE / 2);
2615 +                                       pbuf.drawRect(x-1,y-1,2,2);
2616 +                               }
2617 +                       }
2618 +               }
2619 +               if (_isShowGuide) {
2620 +                       pbuf.setPen(QPen(cyan, 1, DashLine));
2621 +                       if (AS_HORIZONTAL == _asMode || AS_BOTH == _asMode) {
2622 +                               if (0 != _origin.x() || _isUseAllQuadrant) {
2623 +                                       pbuf.drawLine(width() / _margin, 0, width() / _margin, height());
2624 +                               }
2625 +                               pbuf.drawLine(width() * (_margin - 1) / _margin, 0, width() * (_margin - 1) / _margin, height());
2626 +                       }
2627 +
2628 +                       if (AS_VERTICAL == _asMode || AS_BOTH == _asMode) {
2629 +                               if (0 != _origin.y() || _isUseAllQuadrant) {
2630 +                                       pbuf.drawLine(0, height() / _margin, width(), height() / _margin);
2631 +                               }
2632 +                               pbuf.drawLine(0, height() * (_margin - 1) / _margin, width(), height() * (_margin - 1) / _margin);
2633 +                       }
2634 +               }
2635 +
2636 +               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
2637 +                       FNPolygon* p = _draws.at(i);
2638 +                       if (r.intersects(p->boundingRect())) {
2639 +                               p->drawShape(pbuf);
2640 +                       }
2641 +               }
2642 +       } else {
2643 +               int w = _eraser_s;
2644 +               if (PENWIDTH_MAX / 2 < _pen.width()) {
2645 +                       w = _eraser_l;
2646 +               }
2647 +               FNPointList removes;
2648 +               for (uint i = 0; i < _tracks.count(); ++i) {
2649 +                       removes.append(_tracks.at(i));
2650 +               }
2651 +               for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
2652 +                       FNPolygon* p = _draws.at(i);
2653 +                       if (r.intersects(p->boundingRect())) {
2654 +                               bool f = false;
2655 +                               for (uint j = 0; j < _tracks.count(); ++j) {
2656 +                                       QPoint* pts = _tracks.at(j);
2657 +                                       QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w);
2658 +                                       for (uint k = 0; k < p->points().count(); ++k) {
2659 +                                               QPoint& pts2 = p->points().at(k);
2660 +                                               if (selected.contains(pts2)) {
2661 +                                                       f = true;
2662 +                                                       removes.remove(pts);
2663 +                                                       break;
2664 +                                               }
2665 +                                       }
2666 +                                       if (f) {
2667 +                                               break;
2668 +                                       }
2669 +                               }
2670 +                               p->drawShape(pbuf, f);
2671 +                       }
2672 +               }
2673 +               for (uint i = 0; i < removes.count(); ++i) {
2674 +                       _tracks.remove(removes.at(i));
2675 +               }
2676 +               /*
2677 +               if (_isDragging) {
2678 +                       pbuf.setPen(QPen(black, 1));
2679 +                       pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
2680 +               }
2681 +               */
2682 +       }
2683 +       pbuf.end();
2684 +       repaint();
2685 +}
2686 +
2687 +void FNCanvas::changeColor(QRgb c)
2688 +{
2689 +       _pen.setColor(QColor(c));
2690 +}
2691 +
2692 +void FNCanvas::undo()
2693 +{
2694 +       if (MODE_ERASE != _drawMode) {
2695 +               ++_disp_offset;
2696 +               if (_disp_offset > _draws.count()) {
2697 +                       _disp_offset = _draws.count();
2698 +               }
2699 +       } else {
2700 +               _draws = _undobuf;
2701 +               _marks.clear();
2702 +       }
2703 +       redraw();
2704 +}
2705 +
2706 +void FNCanvas::redo()
2707 +{
2708 +       if (MODE_ERASE != _drawMode) {
2709 +               if (0 < _disp_offset) {
2710 +                       --_disp_offset;
2711 +               }
2712 +       }
2713 +       redraw();
2714 +}
2715 +
2716 +void FNCanvas::clearList(FNPolygonList& list)
2717 +{
2718 +       list.setAutoDelete(true);
2719 +       list.clear();
2720 +       list.setAutoDelete(false);
2721 +}
2722 +
2723 +void FNCanvas::clear()
2724 +{
2725 +       _disp_offset = 0;
2726 +       clearList(_draws);
2727 +       _undobuf.clear();
2728 +       setOrigin(0, 0);
2729 +       redraw();
2730 +}
2731 +
2732 +void FNCanvas::viewChanged(bool flg)
2733 +{
2734 +       _tracks.clear();
2735 +       _viewMode = flg;
2736 +       if (_viewMode) {
2737 +               if (_isUseAllQuadrant) {
2738 +                       rebuild();
2739 +               }
2740 +               setOrigin(0, 0);
2741 +       }
2742 +       redraw();
2743 +}
2744 +
2745 +void FNCanvas::redobuf_flush()
2746 +{
2747 +       for (uint i = 0; i < _disp_offset; ++i) {
2748 +               FNPolygon* p = _draws.last();
2749 +               _draws.remove(p);
2750 +               delete p;
2751 +       }
2752 +       _disp_offset = 0;
2753 +}
2754 +
2755 +void FNCanvas::modeChanged(int mode)
2756 +{
2757 +       _tracks.clear();
2758 +       _drawMode = mode;
2759 +       redobuf_flush();
2760 +       if (MODE_ERASE == _drawMode) {
2761 +               _marks.clear();
2762 +               _undobuf = _draws;
2763 +       } else {
2764 +               if (_draws.count() != _undobuf.count()) {
2765 +                       for (uint i = 0; i < _marks.count(); ++i) {
2766 +                               FNPolygon* p = _marks.at(i);
2767 +                               _draws.remove(p);
2768 +                       }
2769 +                       clearList(_marks);
2770 +               }
2771 +       }
2772 +       redraw();
2773 +}
2774 +
2775 +QRect FNCanvas::getMatrix(const QRect& r) const
2776 +{
2777 +       int ox = _origin.x();
2778 +       int oy = _origin.y();
2779 +       const int wide = 100;
2780 +
2781 +       int left = r.left() + ox;
2782 +       int top = r.top() + oy;
2783 +       int right = r.right() + ox;
2784 +       int bottom = r.bottom() + oy;
2785 +       
2786 +       left = (int)(left / wide) * wide;
2787 +       top = (int)(top / wide) * wide;
2788 +       right = (right % wide == 0 && left != right) ? right : (int)((right + wide) / wide) * wide;
2789 +       bottom = (bottom % wide == 0 && top != bottom) ? bottom : (int)((bottom + wide) / wide) * wide;
2790 +       
2791 +       return QRect(left - ox, top - oy, right - left, bottom - top);
2792 +}
2793 +
2794 +void FNCanvas::CR() 
2795 +{
2796 +       if (MODE_ERASE == _drawMode) {
2797 +               return;
2798 +       }
2799 +       if (_isHeadingEnables) {
2800 +               //last\82©\82ç\81A\8d\95û\8cü\82É\8cü\82¯\82Ä\92T\8dõ\82·\82é\81B
2801 +               QRect r = getMatrix(_draws.last()->boundingRect());
2802 +               bool isSearching = true;
2803 +               r.moveBy(-100, 0);
2804 +               while (isSearching) {
2805 +                       isSearching = false;
2806 +                       for (uint i = 0; i < _draws.count(); ++i) {
2807 +                               FNPolygon* p = _draws.at(i);
2808 +                               const QRect& r2 = p->boundingRect();
2809 +                               if (r.intersects(r2)) {
2810 +                                       if (r.left() + 100 > r2.left()) {
2811 +                                               r = getMatrix(r2);
2812 +                                               r.moveBy(-100, 0);
2813 +                                               isSearching = true;
2814 +                                               break;
2815 +                                       }
2816 +                               }
2817 +                       }
2818 +               }
2819 +               r.moveBy(100, 0);
2820 +               //last\82ª\89æ\96Ê\82Ì4/5\88È\89º\82È\82ç\82Î\81A\83X\83N\83\8d\81[\83\8b\83A\83b\83v\82·\82é\81B
2821 +               //\82»\82¤\82Å\82È\82¯\82ê\82Î\81A\83w\83b\83f\83B\83\93\83O\82Ì\82Ý\81B
2822 +               if (_last.y() > height() * 4 / 5) {
2823 +                       setOrigin(_origin.x() + r.x(), _origin.y() + 50);
2824 +               } else {
2825 +                       setOrigin(_origin.x() + r.x(), _origin.y());
2826 +               }
2827 +               _isHeadingEnables = false;
2828 +       } else {
2829 +               //last\82Ì\8eü\88Í\82É\89½\82à\96³\82¢\8fê\8d\87\82Í\81A\8fc\82É\83X\83N\83\8d\81[\83\8b\82·\82é\81B
2830 +               setOrigin(_origin.x(), _origin.y() + 50);
2831 +       }
2832 +}
2833 +
2834 +void FNCanvas::erase()
2835 +{
2836 +       if (MODE_ERASE != _drawMode) {
2837 +               return;
2838 +       }
2839 +       FNPolygonList temp;
2840 +       int w = _eraser_s;
2841 +       if (PENWIDTH_MAX / 2 < _pen.width()) {
2842 +               w = _eraser_l;
2843 +       }
2844 +       QRect r = QRect(0, 0, width(), height());
2845 +       for (uint i = 0; i < _draws.count(); ++i) {
2846 +               FNPolygon* p = _draws.at(i);
2847 +               bool f = false;
2848 +               if (r.intersects(p->boundingRect())) {
2849 +                       for (uint j = 0; j < _tracks.count(); ++j) {
2850 +                               QPoint* pts = _tracks.at(j);
2851 +                               QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w);
2852 +                               for (uint k = 0; k < p->points().count(); ++k) {
2853 +                                       QPoint& pts2 = p->points().at(k);
2854 +                                       if (selected.contains(pts2)) {
2855 +                                               temp.append(p);
2856 +                                               f = true;
2857 +                                               break;
2858 +                                       }
2859 +                               }
2860 +                               if (f) {
2861 +                                       break;
2862 +                               }
2863 +                       }
2864 +               }
2865 +       }
2866 +       for (uint i = 0; i < temp.count(); ++i) {
2867 +               _draws.remove(temp.at(i));
2868 +               _marks.append(temp.at(i));
2869 +       }
2870 +       _tracks.clear();
2871 +       redraw();
2872 +}
2873 +
2874 +void FNCanvas::setPensize(int sz)
2875 +{
2876 +       _pen.setWidth(sz);
2877 +}
2878 +
2879 +bool FNCanvas::exportPNG(const QFileInfo& info, QPixmap& buf)
2880 +{
2881 +       if (0 == info.fileName().length()) {
2882 +               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
2883 +               return false;
2884 +       }
2885 +       if (info.extension(false) != "png") {
2886 +               QMessageBox::warning(0,"FreeNoteQt", "extension '.png' expected.");
2887 +               return false;
2888 +       }
2889 +
2890 +       bool ret = buf.save(info.absFilePath(), "PNG");
2891 +       if (ret) {
2892 +               FNMessageBox::information(0,"FreeNoteQt", "export PNG complete.");
2893 +       } else {
2894 +               QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
2895 +       }
2896 +       return ret;
2897 +}
2898 +
2899 +QString FNCanvas::mkPDFscript(FNPolygon* elm)
2900 +{
2901 +       QString s ="";
2902 +       char buf[1024];
2903 +
2904 +       float r = (float)elm->pen().color().red() / 255.0f;
2905 +       float g = (float)elm->pen().color().green() / 255.0f;
2906 +       float b = (float)elm->pen().color().blue() / 255.0f;
2907 +       s += "q\n";
2908 +       sprintf(buf, "%f %f %f RG\n", r, g, b);
2909 +       s += buf;
2910 +       QPointArray points = elm->points().copy();
2911 +       points.translate(_origin.x(), _origin.y());
2912 +       if (elm->type() == FN_BEZIER) {
2913 +               sprintf(buf, "%d %d m\n", points[0].x(), points[0].y());
2914 +               s += buf;
2915 +               for (uint j = 1; j < points.count(); j += 3) {
2916 +                       sprintf(buf, "%d %d %d %d %d %d c\n",
2917 +                               points[j].x(), points[j].y(),
2918 +                               points[j + 1].x(), points[j + 1].y(),
2919 +                               points[j + 2].x(), points[j + 2].y()
2920 +                               );
2921 +                       s += buf;
2922 +               }
2923 +       } else if (elm->type() == FN_ELLIPSE) {
2924 +               int x = points[0].x();
2925 +               int y = points[0].y();
2926 +               int ex = points[1].x();
2927 +               int ey = points[1].y();
2928 +               int w = ex - x;
2929 +               int h = ey - y;
2930 +               int cx = x + w/2;
2931 +               int cy = y;
2932 +               int x1 = x + 3*w/4;
2933 +               int y1 = y;
2934 +               int x2 = x + w;
2935 +               int y2 = y + h/4;
2936 +               int x3 = x + w;
2937 +               int y3 = y + h/2;
2938 +               
2939 +               sprintf(buf, "%d %d m\n%d %d %d %d %d %d c\n", cx, cy, x1, y1, x2, y2, x3, y3);
2940 +               s += buf;
2941 +               x1 = x + w;
2942 +               y1 = y + 3 * h / 4;
2943 +               x2 = x + 3 * w / 4;
2944 +               y2 = y + h;
2945 +               x3 = x + w/2;
2946 +               y3 = y + h;
2947 +               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
2948 +               s += buf;
2949 +
2950 +               x1 = x + w / 4;
2951 +               y1 = y + h;
2952 +               x2 = x;
2953 +               y2 = y + 3 * h / 4;
2954 +               x3 = x;
2955 +               y3 = y + h / 2;
2956 +               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
2957 +               s += buf;
2958 +               x1 = x;
2959 +               y1 = y + h / 4;
2960 +               x2 = x + w / 4;
2961 +               y2 = y;
2962 +               x3 = x + w / 2;
2963 +               y3 = y;
2964 +               sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3);
2965 +               s += buf;
2966 +       } else {
2967 +               sprintf(buf, "%d %d m\n", points[0].x(), points[0].y());
2968 +               s += buf;
2969 +               for (uint j = 1; j < points.count(); ++j) {
2970 +                       sprintf(buf, "%d %d l\n", points[j].x(), points[j].y());
2971 +                       s += buf;
2972 +               }
2973 +       }
2974 +       sprintf(buf, "%d w\n", elm->pen().width());
2975 +       s += buf;
2976 +       s += "S\n";
2977 +       s += "Q\n";
2978 +       return s;
2979 +}
2980 +
2981 +bool FNCanvas::exportPDF(const QFileInfo& info)
2982 +{
2983 +       if (0 == info.fileName().length()) {
2984 +               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
2985 +               return false;
2986 +       }
2987 +       if (info.extension(false) != "pdf") {
2988 +               QMessageBox::warning(0,"FreeNoteQt", "extension '.pdf' expected.");
2989 +               return false;
2990 +       }
2991 +
2992 +       FILE* fp = NULL;
2993 +       if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
2994 +               QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
2995 +               return false;
2996 +       }
2997 +
2998 +       QPoint o = getTopLeft();
2999 +       rebuild();
3000 +       int wx = 595;
3001 +       int wy = 842;
3002 +       char buf[1024];
3003 +       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
3004 +               FNPolygon* p = _draws.at(i);
3005 +               QRect r = p->boundingRect();
3006 +               r.moveBy(_origin.x(), _origin.y());
3007 +               if (wx < r.right()) {
3008 +                       wx =r.right();
3009 +               }
3010 +               if (wy < r.bottom()) {
3011 +                       wy = r.bottom();
3012 +               }
3013 +       }
3014 +
3015 +       int len = 0;
3016 +       
3017 +       sprintf(buf, "1 0 0 -1 0 %d cm\n", wy);
3018 +       QString cm = buf;
3019 +       len += cm.length();
3020 +
3021 +       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
3022 +               QString s = mkPDFscript(_draws.at(i));
3023 +               len += s.length();
3024 +       }
3025 +
3026 +       QString header = "";
3027 +       header += "%PDF-1.3\n";
3028 +       header += "1 0 obj\n";
3029 +       header += "<<\n";
3030 +       header += "/Type /Page\n";
3031 +       header += "/Parent 3 0 R\n";
3032 +       header += "/Resources\n";
3033 +       header += "<<\n";
3034 +       header += "/ProcSet [ /PDF ]\n";
3035 +       header += ">>\n";
3036 +       sprintf(buf, "/MediaBox [ 0 0 %010d %010d ]\n", wx, wy);
3037 +       header += buf;
3038 +       header += "/Contents 4 0 R\n";
3039 +       header += ">>\n";
3040 +       header += "endobj\n";
3041 +       header += "2 0 obj\n";
3042 +       header += "<<\n";
3043 +       header += "/Type /Catalog\n";
3044 +       header += "/Pages 3 0 R\n";
3045 +       header += "/PageLayout /OneColumn\n";
3046 +       header += "/OpenAction [1 0 R /XYZ null null 1 ]\n";
3047 +       header += ">>\n";
3048 +       header += "endobj\n";
3049 +       header += "3 0 obj\n";
3050 +       header += "<<\n";
3051 +       header += "/Type /Pages\n";
3052 +       header += "/Kids [ 1 0 R ]\n";
3053 +       header += "/Count 1\n";
3054 +       header += ">>\n";
3055 +       header += "endobj\n";
3056 +       header += "4 0 obj\n";
3057 +       sprintf(buf, "<< /Length %010d >>\n", len);
3058 +       header += buf;
3059 +       header += "stream\n";
3060 +
3061 +       QString footer = "";
3062 +       footer += "xref\n";
3063 +       footer += "0 5\n";
3064 +       footer += "0000000000 65535 f \n";
3065 +       footer += "0000000009 00000 n \n";
3066 +       footer += "0000000147 00000 n \n";
3067 +       footer += "0000000257 00000 n \n";
3068 +       footer += "0000000316 00000 n \n";
3069 +       footer += "trailer\n";
3070 +       footer += "<<\n";
3071 +       footer += "/Size 5\n";
3072 +       footer += "/Root 2 0 R\n";
3073 +       footer += ">>\n";
3074 +       footer += "startxref\n";
3075 +
3076 +       len = cm.length();
3077 +       len += header.length();
3078 +       fputs(header, fp);
3079 +       fputs(cm, fp);
3080 +
3081 +       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
3082 +               QString s = mkPDFscript(_draws.at(i));
3083 +               len += s.length();
3084 +               fputs(s, fp);
3085 +       }
3086 +       QString streamfooter = "endstream\nendobj\n";
3087 +       len += streamfooter.length();
3088 +       fputs(streamfooter, fp);
3089 +
3090 +       fputs(footer, fp);
3091 +       sprintf(buf, "%d\n", len);
3092 +       fputs(buf, fp);
3093 +       fputs("%%EOF\n", fp);
3094 +       fclose(fp);
3095 +       if (_isUseAllQuadrant) {
3096 +               setOrigin(-o.x(), -o.y());
3097 +       }
3098 +       FNMessageBox::information(0,"FreeNoteQt", "export PDF complete.");
3099 +       return true;
3100 +}
3101 +
3102 +bool FNCanvas::save(const QFileInfo& info)
3103 +{
3104 +       if (0 == info.fileName().length()) {
3105 +               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
3106 +               return false;
3107 +       }
3108 +       if (info.extension(false) != "free") {
3109 +               QMessageBox::warning(0,"FreeNoteQt", "extension '.free' expected.");
3110 +               return false;
3111 +       }
3112 +       FILE* fp = NULL;
3113 +       if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
3114 +               QMessageBox::warning(0,"FreeNoteQt", "could not save file.");
3115 +               return false;
3116 +       }
3117 +       QPoint o = getTopLeft();
3118 +       rebuild();
3119 +       fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
3120 +       fputs("<freenote version=\"2.0\">\n", fp);
3121 +       char buf[1024];
3122 +       for (uint i = 0; i < _draws.count() - _disp_offset; ++i) {
3123 +               FNPolygon p(*_draws.at(i));
3124 +               p.translate(_origin.x(), _origin.y());
3125 +               if (p.type() == FN_BEZIER) {
3126 +                       sprintf(buf, "\t<bz color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
3127 +               } else if (p.type() == FN_ELLIPSE) {
3128 +                       sprintf(buf, "\t<el color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
3129 +               } else {
3130 +                       sprintf(buf, "\t<po color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
3131 +               }
3132 +               fputs(buf, fp);
3133 +               QPointArray& points = p.points();
3134 +               for (uint j = 0; j < points.count(); ++j) {
3135 +                       QPoint point = points.point(j);
3136 +                       sprintf(buf, "\t\t<p x=\"%d\" y=\"%d\"/>\n", point.x(), point.y());
3137 +                       fputs(buf, fp);
3138 +               }
3139 +               if (p.type() == FN_BEZIER) {
3140 +                       fputs("\t</bz>\n", fp);
3141 +               } else if (p.type() == FN_ELLIPSE) {
3142 +                       fputs("\t</el>\n", fp);
3143 +               } else {
3144 +                       fputs("\t</po>\n", fp);
3145 +               }
3146 +       }
3147 +       fputs("</freenote>\n", fp);
3148 +       fclose(fp);
3149 +       if (_isUseAllQuadrant) {
3150 +               setOrigin(-o.x(), -o.y());
3151 +       }
3152 +       FNMessageBox::information(0, "FreeNoteQt", "save complete.");
3153 +       return true;
3154 +}
3155 +
3156 +bool FNCanvas::load(const QFileInfo& info)
3157 +{
3158 +       if (0 == info.fileName().length()) {
3159 +               QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
3160 +               return false;
3161 +       }
3162 +       if (!info.exists()) {
3163 +               QMessageBox::warning(0,"FreeNoteQt", "file not exists.");
3164 +               return false;
3165 +       }
3166 +       FILE* fp = NULL;
3167 +       if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) {
3168 +               QMessageBox::warning(0,"FreeNoteQt", "could not open file.");
3169 +               return false;
3170 +       }
3171 +       clear();
3172 +
3173 +       QString line;
3174 +       FNPointList points;
3175 +       points.setAutoDelete(true);
3176 +       int c;
3177 +       int w;
3178 +       QPen pen(Qt::black, 1);
3179 +       FNPolygon* polygon;
3180 +       
3181 +       char rdbuf[1024];
3182 +       char buf[1024];
3183 +       QString type = "";
3184 +       while (!feof(fp)) {
3185 +               fgets(rdbuf, sizeof(rdbuf), fp);
3186 +               line = rdbuf;
3187 +               if (-1 != line.find("<fnpolygon ") ||
3188 +                       -1 != line.find("<po ") ||
3189 +                       -1 != line.find("<bz ") ||
3190 +                       -1 != line.find("<el ")
3191 +               ) {
3192 +                       if (-1 != line.find("<el ")) {
3193 +                               type = "Ellipse";
3194 +                       } else if (-1 != line.find("<bz ")) {
3195 +                               type = "Bezier";
3196 +                       } else {
3197 +                               type = "Polygon";
3198 +                       }
3199 +                       points.clear();
3200 +                       int st = line.find("color") + 7;
3201 +                       int ed = line.find("\"", st);
3202 +                       strcpy(buf, line.mid(st, ed - st).utf8());
3203 +                       sscanf(buf, "%x", &c);
3204 +                       st = line.find("width") + 7;
3205 +                       ed = line.find("\"", st);
3206 +                       strcpy(buf, line.mid(st, ed - st).utf8());
3207 +                       sscanf(buf, "%d", &w);
3208 +               } else if (-1 != line.find("<point ") ||
3209 +                       -1 != line.find("<p ")
3210 +                       ) {
3211 +                       int st = line.find("x=") + 3;
3212 +                       int ed = line.find("\"", st);
3213 +                       strcpy(buf, line.mid(st, ed - st).utf8());
3214 +                       int x;
3215 +                       sscanf(buf, "%d", &x);
3216 +
3217 +                       st = line.find("y=") + 3;
3218 +                       ed = line.find("\"", st);
3219 +                       strcpy(buf, line.mid(st, ed - st).utf8());
3220 +                       int y;
3221 +                       sscanf(buf, "%d", &y);
3222 +                       points.append(createPts(x, y)); //\83o\83O\91Î\8dô
3223 +               } else if (-1 != line.find("</fnpolygon") || 
3224 +                       -1 != line.find("</bz") ||
3225 +                       -1 != line.find("</el") ||
3226 +                       -1 != line.find("</po")) {
3227 +                       pen.setColor((QRgb)c);
3228 +                       pen.setWidth(w);
3229 +                       if (type == "Bezier") {
3230 +                               _draws.append(polygon = createBezier(pen)); //\83o\83O\91Î\8dô
3231 +                       } else if (type == "Ellipse") {
3232 +                               _draws.append(polygon = createEllipse(pen)); //\83o\83O\91Î\8dô
3233 +                       } else {
3234 +                               _draws.append(polygon = createPolygon(pen)); //\83o\83O\91Î\8dô
3235 +                       }
3236 +                       polygon->setPoints(points);
3237 +                       points.clear();
3238 +               }
3239 +       }
3240 +       fclose(fp);
3241 +       int x = 0;
3242 +       int y = 0;
3243 +       for (uint i = 0; i < _draws.count(); ++i) {
3244 +               if (y > _draws.at(i)->boundingRect().top()) {
3245 +                       y = _draws.at(i)->boundingRect().top();
3246 +               }
3247 +               if (x > _draws.at(i)->boundingRect().left()) {
3248 +                       x = _draws.at(i)->boundingRect().left();
3249 +               }
3250 +       }
3251 +       for (uint i = 0; i < _draws.count(); ++i) {
3252 +               _draws.at(i)->translate(-x, -y);
3253 +       }
3254 +       redraw();
3255 +       FNMessageBox::information(0,"FreeNoteQt", "load complete.");
3256 +
3257 +       return true;
3258 +}
3259 +
3260 +FNPolygon* FNCanvas::createPolygon(QPen& pen)
3261 +{
3262 +       return new FNPolygon(pen);
3263 +}
3264 +
3265 +FNPolygon* FNCanvas::createBezier(QPen& pen)
3266 +{
3267 +       return new FNBezier(pen);
3268 +}
3269 +
3270 +
3271 +FNPolygon* FNCanvas::createEllipse(QPen& pen)
3272 +{
3273 +       return new FNEllipse(pen);
3274 +}
3275 +
3276 +QPoint* FNCanvas::createPts(int x, int y) 
3277 +{
3278 +       return new QPoint(x, y);
3279 +}
3280 +
3281 +void FNCanvas::setGuide(bool f)
3282 +{
3283 +       _isShowGuide = f;
3284 +       redraw();
3285 +}