| 1 40 41 package gnu.jpdf; 42 43 44 45 import java.awt.*; 46 47 import java.awt.image.*; 48 49 import java.io.*; 50 51 import java.util.*; 52 53 54 55 74 75 public class PDFGraphics extends Graphics implements Serializable 76 77 { 78 79 80 81 102 103 104 105 106 107 109 111 113 115 117 119 121 123 125 127 129 131 132 133 138 139 protected Rectangle media; 140 141 142 143 148 149 private int mediaRot; 150 151 152 153 158 159 protected int trax; 160 161 162 163 168 169 protected int tray; 170 171 172 173 182 183 private String pre_np; 184 185 186 187 194 195 private boolean inStroke; 196 197 198 199 210 211 private int lx; 213 214 215 226 227 private int ly; 229 230 231 238 239 private boolean inText; 241 242 243 250 251 private boolean newFont; 253 254 255 262 263 private int tx; 265 266 267 274 275 private int ty; 277 278 279 284 285 private Color color; 286 287 288 289 294 295 private PDFFont pdffont; 296 297 298 299 304 305 private Font font; 306 307 308 309 314 315 private PrintWriter pw; 316 317 318 319 324 325 private PDFPage page; 326 327 328 329 336 337 private boolean child; 338 339 340 341 342 343 344 345 358 359 protected PDFGraphics createGraphic(PDFPage page, 360 361 PrintWriter pw) 362 363 { 364 365 PDFGraphics g = new PDFGraphics(); 366 367 g.init(page,pw); 368 369 return g; 370 371 } 372 373 374 375 376 377 378 379 386 387 protected void init(PDFPage page) { 388 389 this.page = page; 390 391 392 393 395 child = false; 396 397 398 399 401 PDFStream stream = new PDFStream(); 402 403 page.getPDFDocument().add(stream); 404 405 page.add(stream); 406 407 pw = stream.getWriter(); 408 409 410 411 413 clipRectangle = new Rectangle(page.getMedia()); 414 415 416 417 419 init(); 420 421 } 422 423 424 425 434 435 protected void init(PDFPage page,PrintWriter pw) { 436 437 this.page = page; 438 439 this.pw = pw; 440 441 442 443 445 447 child = true; 448 449 450 451 453 init(); 454 455 } 456 457 458 459 478 479 private void init() { 480 481 483 if(child) { 484 485 pw.print("q "); 486 487 } 488 489 490 491 493 setDefaultLineWidth(); 494 495 496 497 499 501 color = Color.black; 502 503 505 507 508 509 511 media = page.getMedia(); 512 513 mediaRot = page.getOrientation(); 514 515 516 517 519 if(!child) { 520 521 setOrientation(); 522 523 } 524 525 } 526 527 528 529 530 531 538 539 public PrintWriter getWriter() { 540 541 return pw; 542 543 } 544 545 546 547 548 549 556 557 public PDFPage getPage() { 558 559 return page; 560 561 } 562 563 564 565 566 567 568 569 588 589 public Graphics create() { 590 591 closeBlock(); 592 593 594 595 PDFGraphics g = createGraphic(page,pw); 596 597 598 599 601 g.media = new Rectangle(media); 602 603 g.trax = trax; 604 605 g.tray = tray; 606 607 g.clipRectangle = new Rectangle(clipRectangle); 608 609 610 611 return (Graphics) g; 612 613 } 615 616 617 618 619 620 621 646 647 public void dispose() { 648 649 closeBlock(); 650 651 if(child) { 652 653 pw.println("Q"); 655 } 656 657 else { 658 659 pw.close(); 661 } 662 663 } 664 665 666 667 668 669 670 671 673 675 677 678 679 681 682 683 696 697 public void clearRect(int x,int y,int w,int h) { 698 699 closeBlock(); 700 701 pw.print("q 1 1 1 RG "); 703 drawRect(x,y,w,h); 704 705 closeBlock("B Q"); 707 } 708 709 710 711 712 713 728 729 public void drawRect(int x,int y,int w,int h) { 730 731 newPath(); 732 733 pw.print(cxy(x,y)+cwh(w,h)+"re "); 735 lx=x; 737 ly=y; 739 741 } 742 743 744 745 746 747 780 781 public void draw3DRect(int x, int y, 782 783 int width, int height, boolean raised) { 784 785 787 } 788 789 790 791 792 793 810 811 public void fill3DRect(int x, int y, 812 813 int width, int height, boolean raised) { 814 815 817 } 818 819 820 821 822 823 838 839 public void fillRect(int x,int y,int w,int h) { 840 841 843 845 closeBlock(); 846 847 drawRect(x,y,w,h); 848 849 closeBlock("B"); 851 } 852 853 854 855 857 858 859 878 879 public void fillRoundRect(int x,int y,int w,int h,int aw,int ah) { 880 881 } 882 883 884 885 904 905 public void drawRoundRect(int x,int y,int w,int h,int aw,int ah) { 906 907 } 908 909 910 911 913 914 915 930 931 public void drawOval(int x,int y,int w,int h) { 932 933 drawArc(x, y, w, h, 0, 360); 934 935 } 936 937 938 939 954 955 public void fillOval(int x,int y,int w,int h) { 956 957 fillArc(x, y, w, h, 0, 360); 958 959 } 960 961 962 963 965 966 967 978 979 public void drawPolygon(int[] xp,int[] yp,int np) { 980 981 polygon(xp,yp,np); 982 983 closeBlock("s"); 985 } 986 987 988 989 1000 1001 public void drawPolyline(int[] xp,int[] yp,int np) { 1002 1003 polygon(xp,yp,np); 1004 1005 1007 } 1008 1009 1010 1011 1022 1023 public void fillPolygon(int[] xp,int[] yp,int np) { 1024 1025 closeBlock(); 1027 polygon(xp,yp,np); 1028 1029 closeBlock("b"); 1031 } 1032 1033 1034 1035 1037 1038 1039 1054 1055 public boolean drawImage(Image img,int x,int y,ImageObserver obs) { 1056 1057 return drawImage(img,x,y,img.getWidth(obs),img.getHeight(obs),obs); 1058 1059 } 1060 1061 1062 1063 1094 1095 public boolean drawImage(Image img,int x,int y,int w,int h, 1096 1097 ImageObserver obs) { 1098 1099 closeBlock(); 1100 1101 PDFImage image = new PDFImage(img,x,y,w,h,obs); 1102 1103 1105 page.getPDFDocument().setImageName(image); 1106 1107 page.getPDFDocument().add(image); 1108 1109 page.addToProcset("/ImageC"); 1110 1111 1112 1113 1115 1118 1119 page.addImageResource(image.getName() + " " + image.getSerialID() + 1120 1121 " 0 R"); 1122 1123 1124 1125 1127 pw.print("q " + 1128 1129 image.getWidth() + 1130 1131 " 0 0 " + 1132 1133 image.getHeight() + 1134 1135 " " + x + " " + 1136 1137 ((int)page.getDimension().getHeight()-y-image.getHeight()) + 1138 1139 " cm \n" + image.getName() + " Do\nQ\n"); 1140 1141 return false; 1142 1143 } 1144 1145 1146 1147 1148 1149 1168 1169 public boolean drawImage(Image img,int x,int y,Color bgcolor, 1170 1171 ImageObserver obs) { 1172 1173 return drawImage(img,x,y,img.getWidth(obs),img.getHeight(obs), 1174 1175 bgcolor,obs); 1176 1177 } 1178 1179 1180 1181 1204 1205 public boolean drawImage(Image img,int x,int y,int w,int h, 1206 1207 Color bgcolor,ImageObserver obs) { 1208 1209 closeBlock(); 1210 1211 pw.print("q "); 1213 Color c = color; 1215 setColor(bgcolor); 1217 drawRect(x,y,w,h); 1218 1219 closeBlock("B Q"); 1221 color = c; 1223 return drawImage(img,x,y,img.getWidth(obs),img.getHeight(obs),obs); 1224 1225 } 1226 1227 1228 1229 1260 1261 public boolean drawImage(Image img,int dx1,int dy1,int dx2, 1262 1263 int dy2,int sx1,int sy1,int sx2,int sy2, 1264 1265 ImageObserver obs) { 1266 1267 1269 return false; 1270 1271 } 1272 1273 1274 1275 1308 1309 public boolean drawImage(Image img,int dx1,int dy1,int dx2, 1310 1311 int dy2,int sx1,int sy1,int sx2,int sy2, 1312 1313 Color bgcolor,ImageObserver obs) { 1314 1315 return false; 1316 1317 } 1318 1319 1320 1321 1323 1324 1325 1330 1331 protected Rectangle clipRectangle; 1332 1333 1334 1335 1348 1349 public void clipRect(int x,int y,int w,int h) { 1350 1351 setClip(x,y,w,h); 1352 1353 } 1354 1355 1356 1357 1370 1371 public void setClip(int x,int y,int w,int h) { 1372 1373 clipRectangle = new Rectangle(x,y,w,h); 1374 1375 closeBlock(); 1377 drawRect(x,y,w,h); 1378 1379 closeBlock("W n"); 1381 } 1382 1383 1384 1385 1394 1395 public void setClip(Shape s) { 1396 1397 Rectangle r = s.getBounds(); 1398 1399 setClip(r.x,r.y,r.width,r.height); 1400 1401 } 1402 1403 1404 1405 1420 1421 public void clipPolygon(Polygon p) { 1422 1423 closeBlock(); 1425 polygon(p.xpoints,p.ypoints,p.npoints); 1426 1427 closeBlock("W"); 1429 clipRectangle = p.getBounds(); 1430 1431 } 1432 1433 1434 1435 1436 1437 1444 1445 public Rectangle getClipBounds() { 1446 1447 return clipRectangle; 1448 1449 } 1450 1451 1452 1453 1455 1456 1457 1464 1465 public Color getColor() { 1466 1467 return color; 1468 1469 } 1470 1471 1472 1473 1480 1481 public void setColor(Color c) { 1482 1483 color = c; 1484 1485 double r = ((double)c.getRed())/255.0; 1486 1487 double g = ((double)c.getGreen())/255.0; 1488 1489 double b = ((double)c.getBlue())/255.0; 1490 1491 closeBlock(); 1493 pw.println(""+r+" "+g+" "+b+" rg "+r+" "+g+" "+b+" RG"); 1494 1495 } 1496 1497 1498 1499 1504 1505 public void setPaintMode() { 1506 1507 } 1508 1509 1510 1511 1518 1519 public void setXORMode(Color c1) { 1520 1521 } 1522 1523 1524 1525 1527 1528 1529 1542 1543 public FontMetrics getFontMetrics(Font font) { 1544 1545 Frame dummy = new Frame(); 1546 1547 dummy.addNotify(); 1548 1549 Image image = dummy.createImage(100, 100); 1550 1551 if (image == null) { 1552 1553 System.err.println("getFontMetrics: image is null"); 1554 1555 } 1556 1557 Graphics graphics = image.getGraphics(); 1558 1559 return graphics.getFontMetrics(font); 1560 1561 1562 1563 } 1564 1565 1566 1567 1574 1575 public Font getFont() { 1576 1577 if(font==null) 1578 1579 setFont(new Font("SansSerif",Font.PLAIN,12)); 1580 1581 return font; 1582 1583 } 1584 1585 1586 1587 1594 1595 public void setFont(Font f) { 1596 1597 1599 if(font!=f) { 1600 1601 font = f; 1602 1603 pdffont = page.getFont("/Type1",f.getName(),f.getStyle()); 1604 1605 1606 1607 1609 newFont = true; 1610 1611 } 1612 1613 } 1614 1615 1616 1617 1630 1631 public void drawString(String s,int x,int y) { 1632 1633 newTextBlock(x,y); 1634 1635 pw.println(PDFStringHelper.makePDFString(s)+" Tj"); 1636 1637 } 1638 1639 1640 1641 1642 1643 1644 1645 1662 1663 public void drawBytes(byte[] data, int offset, int length, int x, int y) { 1664 1665 1666 1667 } 1668 1669 1670 1671 1672 1673 1675 1676 1677 1682 1683 void closeBlock() { 1684 1685 closeBlock("S"); 1686 1687 } 1688 1689 1690 1691 1702 1703 void closeBlock(String code) { 1704 1705 if(inText) { 1706 1707 pw.println("ET Q"); 1708 1709 setOrientation(); 1711 } 1712 1713 1714 1715 if(inStroke) { 1716 1717 pw.println(code); 1718 1719 } 1720 1721 1722 1723 inStroke=inText=false; 1724 1725 } 1726 1727 1728 1729 1736 1737 void newPath() { 1738 1739 if(inText) { 1740 1741 closeBlock(); 1742 1743 } 1744 1745 if(!inStroke) { 1746 1747 if(pre_np!=null) { 1748 1749 pw.print(pre_np); 1751 pre_np = null; 1752 1753 } 1754 1755 pw.print("n "); 1756 1757 } 1758 1759 1760 1761 inText=false; 1762 1763 inStroke=true; 1764 1765 1766 1767 1769 lx = ly = -9999; 1770 1771 } 1772 1773 1774 1775 1796 1797 void newTextBlock(int x,int y) { 1798 1799 1801 if(inStroke) { 1802 1803 closeBlock(); 1804 1805 } 1806 1807 1809 1811 if(!inText) { 1812 1813 1815 getFont(); 1816 1817 1818 1819 pw.print("q BT "); 1820 1821 tx=ty=0; 1822 1823 1824 1825 1827 switch(mediaRot) { 1828 1829 case 0: 1831 1833 break; 1834 1835 1836 1837 case 90: 1839 pw.println("0 1 -1 0 0 0 Tm"); 1841 break; 1842 1843 1844 1845 case 180: 1847 pw.println("1 0 0 -1 0 0 Tm"); 1848 1849 break; 1850 1851 1852 1853 case 270: 1855 pw.println("0 -1 1 0 0 0 Tm"); 1857 break; 1858 1859 } 1860 1861 1862 1863 1865 pw.print(txy(x,y)+"Td "); 1866 1867 1868 1869 } else { 1870 1871 1873 1875 1877 1879 pw.print(twh(x,y,tx,ty)+"Td "); 1880 1881 } 1882 1883 1884 1885 1887 tx = x; 1888 1889 ty = y; 1890 1891 1892 1893 if(newFont || !inText) 1894 1895 pw.print(pdffont.getName()+" "+font.getSize()+" Tf "); 1896 1897 1898 1899 1901 1902 1903 inStroke = newFont = false; 1904 1905 inText = true; 1906 1907 } 1908 1909 1910 1911 1912 1913 1930 1931 public void copyArea(int x,int y,int w,int h,int dx,int dy) { 1932 1933 1935 1937 } 1938 1939 1940 1941 1943 1944 1945 1964 1965 public void drawLine(int x1,int y1,int x2,int y2) { 1966 1967 moveto(x1,y1); 1968 1969 lineto(x2,y2); 1970 1971 } 1972 1973 1974 1975 1984 1985 public void translate(int x,int y) { 1986 1987 trax+=x; 1988 1989 tray+=y; 1990 1991 1993 1995 1997 } 1998 1999 2000 2001 2003 2005 2007 2008 2009 2026 2027 public void drawArc(int x,int y,int w,int h,int sa,int aa) { 2028 2029 w=w>>1; 2030 2031 h=h>>1; 2032 2033 x+=w; 2034 2035 y+=h; 2036 2037 2038 2039 arc((double)x,(double)y, 2040 2041 (double)w,(double)h, 2042 2043 (double)-sa,(double)(-sa-aa), 2044 2045 false); 2046 2047 } 2048 2049 2050 2051 2068 2069 public void fillArc(int x,int y,int w,int h,int sa,int aa) { 2070 2071 2073 2075 2077 2079 2081 2083 2085 closeBlock(); 2086 2087 drawArc(x,y,w,h,sa,aa); 2088 2089 lineto(x+(w>>1),y+(h>>1)); 2090 2091 closeBlock("b"); 2093 } 2094 2095 2096 2097 2099 2101 2103 2104 2105 2114 2115 public void moveto(int x,int y) { 2116 2117 newPath(); 2118 2119 if(lx!=x && ly!=y) 2120 2121 pw.print(cxy(x,y)+"m "); 2122 2123 lx=x; 2124 2125 ly=y; 2126 2127 } 2128 2129 2130 2131 2140 2141 public void moveto(double x,double y) { 2142 2143 newPath(); 2144 2145 2147 pw.print(cxy(x,y)+"m "); 2148 2149 lx=(int)x; 2150 2151 ly=(int)y; 2152 2153 } 2154 2155 2156 2157 2166 2167 public void lineto(int x,int y) { 2168 2169 newPath(); 2170 2171 if(lx!=x && ly!=y) 2172 2173 pw.print(cxy(x,y)+"l "); 2174 2175 lx=x; 2176 2177 ly=y; 2178 2179 } 2180 2181 2182 2183 2192 2193 public void lineto(double x,double y) { 2194 2195 newPath(); 2196 2197 2199 pw.print(cxy(x,y)+"l "); 2200 2201 lx=(int)x; 2202 2203 ly=(int)y; 2204 2205 } 2206 2207 2208 2209 2216 2217 public void setLineWidth(double w) { 2218 2219 closeBlock(); 2221 pw.println(""+w+" w"); 2222 2223 } 2224 2225 2226 2227 2234 2235 public void setDefaultLineWidth() { 2236 2237 closeBlock(); 2239 pw.println("1 w"); 2240 2241 } 2242 2243 2244 2245 2264 2265 public void polygon(int[] xp,int[] yp,int np) { 2266 2267 2269 moveto(xp[0],yp[0]); 2270 2271 for(int i=1;i<np;i++) 2272 2273 lineto(xp[i],yp[i]); 2274 2275 } 2276 2277 2278 2279 2304 2305 public void curveto(int x1,int y1,int x2,int y2,int x3,int y3) { 2306 2307 newPath(); 2308 2309 pw.println(cxy(x1,y1)+cxy(x2,y2)+cxy(x3,y3)+"c"); 2310 2311 lx=x3; 2312 2313 ly=y3; 2314 2315 } 2316 2317 2318 2319 2344 2345 public void curveto(double x1,double y1,double x2,double y2,double x3,double y3) { 2346 2347 newPath(); 2348 2349 pw.println(cxy(x1,y1)+cxy(x2,y2)+cxy(x3,y3)+"c"); 2350 2351 lx=(int)x3; 2352 2353 ly=(int)y3; 2354 2355 } 2356 2357 2358 2359 2380 2381 public void curveto(int x1,int y1,int x2,int y2) { 2382 2383 newPath(); 2384 2385 pw.println(cxy(x1,y1)+cxy(x2,y2)+"v"); 2386 2387 lx=x2; 2388 2389 ly=y2; 2390 2391 } 2392 2393 2394 2395 2416 2417 public void curveto(double x1,double y1,double x2,double y2) { 2418 2419 newPath(); 2420 2421 pw.println(cxy(x1,y1)+cxy(x2,y2)+"v"); 2422 2423 lx=(int)x2; 2424 2425 ly=(int)y2; 2426 2427 } 2428 2429 2430 2431 2452 2453 public void curveto2(int x1,int y1,int x2,int y2) { 2454 2455 newPath(); 2456 2457 pw.println(cxy(x1,y1)+cxy(x2,y2)+"y"); 2458 2459 lx=x2; 2460 2461 ly=y2; 2462 2463 } 2464 2465 2466 2467 2488 2489 public void curveto2(double x1,double y1,double x2,double y2) { 2490 2491 newPath(); 2492 2493 pw.println(cxy(x1,y1)+cxy(x2,y2)+"y"); 2494 2495 lx=(int)x2; 2496 2497 ly=(int)y2; 2498 2499 } 2500 2501 2502 2503 2504 2505 2507 2509 2511 2513 2515 2516 2517 2522 2523 private static final double degrees_to_radians = Math.PI/180.0; 2524 2525 2526 2527 2550 2551 public void arc(double axc,double ayc, 2552 2553 double width,double height, 2554 2555 double ang1,double ang2, 2556 2557 boolean clockwise) { 2558 2559 2560 2561 double adiff; 2562 2563 double x0, y0; 2564 2565 double x3r, y3r; 2566 2567 boolean first = true; 2568 2569 2570 2571 2573 2575 2577 2579 2581 2583 2584 2585 double ang1r = (ang1%360.0)*degrees_to_radians; 2586 2587 2588 2589 double sin0 = Math.sin(ang1r); 2590 2591 double cos0 = Math.cos(ang1r); 2592 2593 2594 2595 x0 = axc + width*cos0; 2596 2597 y0 = ayc + height*sin0; 2598 2599 2600 2601 2603 if( !clockwise ) { 2604 2605 2607 while ( ang1 < ang2 ) ang2 -= 360.0; 2608 2609 while ( (adiff = ang2 - ang1) < -90.0 ) { 2610 2611 double w = sin0; sin0 = -cos0; cos0 = w; 2612 2613 x3r = axc + width*cos0; 2614 2615 y3r = ayc + height*sin0; 2616 2617 arc_add(first, 2618 2619 width, height, 2620 2621 x0, y0, 2622 2623 x3r, y3r, 2624 2625 (x0 + width*cos0), 2626 2627 (y0 + height*sin0) 2628 2629 ); 2630 2631 2632 2633 x0 = x3r; 2634 2635 y0 = y3r; 2636 2637 ang1 -= 90.0; 2638 2639 first = false; 2640 2641 } 2642 2643 } else { 2644 2645 2647 while ( ang2 < ang1 ) ang2 += 360.0; 2648 2649 while ( (adiff = ang2 - ang1) > 90.0 ) { 2650 2651 double w = cos0; cos0 = -sin0; sin0 = w; 2652 2653 x3r = axc + width*cos0; 2654 2655 y3r = ayc + height*sin0; 2656 2657 arc_add(first, 2658 2659 width, height, 2660 2661 x0, y0, 2662 2663 x3r, y3r, 2664 2665 (x0 + width*cos0), 2666 2667 (y0 + height*sin0) 2668 2669 ); 2670 2671 2672 2673 x0 = x3r; 2674 2675 y0 = y3r; 2676 2677 ang1 += 90.0; 2678 2679 first = false; 2680 2681 } 2682 2683 } 2684 2685 2686 2687 2689 2691 double trad = Math.tan(adiff * (degrees_to_radians / 2)); 2692 2693 double ang2r = ang2 * degrees_to_radians; 2694 2695 double xt = x0 - trad * width*sin0; 2696 2697 double yt = y0 + trad * height*cos0; 2698 2699 arc_add(first, width, height, x0, y0, 2700 2701 (axc + width * Math.cos(ang2r)), 2702 2703 (ayc + height * Math.sin(ang2r)), 2704 2705 xt, yt); 2706 2707 } 2708 2709 2710 2711 2738 2739 private void arc_add(boolean first, 2740 2741 double w,double h, 2742 2743 double x0,double y0, 2744 2745 double x3,double y3, 2746 2747 double xt,double yt) { 2748 2749 double dx = xt - x0, dy = yt - y0; 2750 2751 double dist = dx*dx + dy*dy; 2752 2753 double w2 = w*w, h2=h*h; 2754 2755 double r2 = w2+h2; 2756 2757 2758 2759 double fw = 0.0, fh = 0.0; 2760 2761 if(dist < (r2*1.0e8)) { 2762 2763 2765 fw = (w2 != 0.0) ? ((4.0/3.0)/(1+Math.sqrt(1+dist/w2))) : 0.0; 2766 2767 fh = (h2 != 0.0) ? ((4.0/3.0)/(1+Math.sqrt(1+dist/h2))) : 0.0; 2768 2769 } 2770 2771 2772 2773 2775 if(first) 2776 2777 moveto(x0,y0); 2778 2779 2780 2781 double x = x0+((xt-x0)*fw); 2782 2783 double y = y0+((yt-y0)*fh); 2784 2785 x0 = x3+((xt-x3)*fw); 2786 2787 y0 = y3+((yt-y3)*fh); 2788 2789 2790 2791 2793 curveto(x,y,x0,y0,x3,y3); 2794 2795 } 2796 2797 2798 2799 2816 2817 public void setOrientation() { 2818 2819 mediaRot = page.getOrientation(); 2820 2821 switch(mediaRot) 2822 2823 { 2824 2825 case 0: 2827 2829 break; 2830 2831 2832 2833 case 90: 2835 2837 2839 2841 break; 2842 2843 2844 2845 case 180: 2847 2849 break; 2850 2851 2852 2853 case 270: 2855 2857 2859 break; 2860 2861 } 2862 2863 } 2864 2865 2866 2867 2878 2879 private String cxy(int x,int y) { 2880 2881 return cxy((double)x,(double)y); 2882 2883 } 2884 2885 2886 2887 2898 2899 private String cxy(double x,double y) { 2900 2901 double nx=x,ny=y; 2903 double mw = (double)(media.width); 2904 2905 double mh = (double)(media.height); 2906 2907 2908 2909 2911 x-=trax; 2912 2913 y-=tray; 2914 2915 2916 2917 switch(mediaRot) { 2918 2919 case 0: 2920 2921 2923 2925 ny = mh - y; 2926 2927 break; 2928 2929 2930 2931 case 90: 2932 2933 2935 nx = y; 2936 2937 ny = x; 2938 2939 break; 2940 2941 2942 2943 case 180: 2944 2945 2947 nx = mw - x; 2948 2949 2951 break; 2952 2953 2954 2955 case 270: 2956 2957 2959 nx = mw - y; 2960 2961 ny = mh - x; 2962 2963 break; 2964 2965 } 2966 2967 2968 2969 return ""+nx+" "+ny+" "; 2970 2971 } 2972 2973 2974 2975 2986 2987 private String cwh(int w,int h) { 2988 2989 return cwh((double)w,(double)h); 2990 2991 } 2992 2993 2994 2995 3006 3007 private String cwh(double w,double h) { 3008 3009 double nw=w,nh=h; 3011 3012 3013 switch(mediaRot) { 3014 3015 case 0: 3016 3017 3019 3021 nh = -h; 3022 3023 break; 3024 3025 3026 3027 case 90: 3028 3029 3031 nw = h; 3032 3033 nh = w; 3034 3035 break; 3036 3037 3038 3039 case 180: 3040 3041 3043 nw = -w; 3044 3045 3047 break; 3048 3049 3050 3051 case 270: 3052 3053 3055 nw = -h; 3056 3057 nh = -w; 3058 3059 break; 3060 3061 } 3062 3063 3064 3065 return ""+nw+" "+nh+" "; 3066 3067 } 3068 3069 3070 3071 3082 3083 private String txy(int x,int y) { 3084 3085 int nx=x, ny=y; 3086 3087 int mw = media.width; 3088 3089 int mh = media.height; 3090 3091 3092 3093 3095 x+=trax; 3096 3097 y+=tray; 3098 3099 3100 3101 switch(mediaRot) 3102 3103 { 3104 3105 case 0: 3106 3107 3109 3111 ny = mh - y; 3112 3113 break; 3114 3115 3116 3117 case 90: 3118 3119 3121 3123 3125 nx = x; 3126 3127 ny = -y; 3128 3129 break; 3130 3131 3132 3133 case 180: 3134 3135 3137 3139 nx = mw - x; 3140 3141 3143 break; 3144 3145 3146 3147 case 270: 3148 3149 3151 3153 nx = mw - y; 3154 3155 ny = mh - x; 3156 3157 break; 3158 3159 } 3160 3161 3162 3163 return ""+nx+" "+ny+" "; 3164 3165 } 3166 3167 3168 3169 3184 3185 private String twh(int x,int y,int tx,int ty) { 3186 3187 int nx=x, ny=y; 3188 3189 int ntx=tx, nty=ty; 3190 3191 int mw = media.width; 3192 3193 int mh = media.height; 3194 3195 int sx=1,sy=1; 3196 3197 switch(mediaRot) 3198 3199 { 3200 3201 case 0: 3202 3203 3205 3207 ny = mh - y; 3208 3209 nty = mh - ty; 3210 3211 break; 3212 3213 3214 3215 case 90: 3216 3217 3219 3221 3223 3225 3227 3229 nx = x; 3230 3231 ny = -y; 3232 3233 ntx = tx; 3234 3235 nty = -ty; 3236 3237 3239 break; 3240 3241 3242 3243 case 180: 3244 3245 3247 3249 nx = mw - x; 3250 3251 3253 break; 3254 3255 3256 3257 case 270: 3258 3259 3261 3263 nx = mw - y; 3264 3265 ny = mh - x; 3266 3267 break; 3268 3269 } 3270 3271 3272 3273 nx = sx*(nx-ntx); 3274 3275 ny = sy*(ny-nty); 3276 3277 return ""+nx+" "+ny+" "; 3278 3279 } 3280 3281 3282 3283 3284 3285 3286 3287 3296 3297 public Shape getClip() { 3298 3299 return null; 3300 3301 } 3302 3303 3304 3305 3316 3317 public void drawString(java.text.AttributedCharacterIterator aci, 3318 3319 int x,int y) { 3320 3321 } 3322 3323 3324 3325} 3327 3328 3329 | Popular Tags |