PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ppt/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java

https://github.com/minstrelsy/POI-Android
Java | 1773 lines | 382 code | 107 blank | 1284 comment | 17 complexity | c1eed61b5e85ccbd507d7e9acd97a919 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.model;
  16. import and.awt.*;
  17. import and.awt.Shape;
  18. import and.awt.font.FontRenderContext;
  19. import and.awt.font.GlyphVector;
  20. import and.awt.image.*;
  21. import and.awt.image.renderable.RenderableImage;
  22. import and.awt.geom.*;
  23. import java.text.AttributedCharacterIterator;
  24. import java.util.Map;
  25. import net.pbdavey.awt.Graphics2D;
  26. import net.pbdavey.awt.RenderingHints;
  27. import org.apache.poi.hslf.usermodel.RichTextRun;
  28. import org.apache.poi.hslf.exceptions.HSLFException;
  29. import org.apache.poi.util.POILogger;
  30. import org.apache.poi.util.POILogFactory;
  31. /**
  32. * Translates Graphics2D calls into PowerPoint.
  33. *
  34. * @author Yegor Kozlov
  35. */
  36. public final class PPGraphics2D extends Graphics2D implements Cloneable {
  37. protected POILogger log = POILogFactory.getLogger(this.getClass());
  38. //The ppt object to write into.
  39. private ShapeGroup _group;
  40. private AffineTransform _transform;
  41. private Stroke _stroke;
  42. private Paint _paint;
  43. private Font _font;
  44. private Color _foreground;
  45. private Color _background;
  46. private RenderingHints _hints;
  47. /**
  48. * Construct Java Graphics object which translates graphic calls in ppt drawing layer.
  49. *
  50. * @param group The shape group to write the graphics calls into.
  51. */
  52. public PPGraphics2D(ShapeGroup group){
  53. this._group = group;
  54. _transform = new AffineTransform();
  55. _stroke = new BasicStroke();
  56. _paint = Color.black;
  57. _font = new Font("Arial", Font.PLAIN, 12);
  58. _background = Color.black;
  59. _foreground = Color.white;
  60. _hints = new RenderingHints(null);
  61. }
  62. /**
  63. * @return the shape group being used for drawing
  64. */
  65. public ShapeGroup getShapeGroup(){
  66. return _group;
  67. }
  68. /**
  69. * Gets the current font.
  70. * @return this graphics context's current font.
  71. * @see and.awt.Font
  72. * @see and.awt.Graphics#setFont(Font)
  73. */
  74. public Font getFont(){
  75. return _font;
  76. }
  77. /**
  78. * Sets this graphics context's font to the specified font.
  79. * All subsequent text operations using this graphics context
  80. * use this font.
  81. * @param font the font.
  82. * @see and.awt.Graphics#getFont
  83. * @see and.awt.Graphics#drawString(java.lang.String, int, int)
  84. * @see and.awt.Graphics#drawBytes(byte[], int, int, int, int)
  85. * @see and.awt.Graphics#drawChars(char[], int, int, int, int)
  86. */
  87. public void setFont(Font font){
  88. this._font = font;
  89. }
  90. /**
  91. * Gets this graphics context's current color.
  92. * @return this graphics context's current color.
  93. * @see and.awt.Color
  94. * @see and.awt.Graphics#setColor
  95. */
  96. public Color getColor(){
  97. return _foreground;
  98. }
  99. /**
  100. * Sets this graphics context's current color to the specified
  101. * color. All subsequent graphics operations using this graphics
  102. * context use this specified color.
  103. * @param c the new rendering color.
  104. * @see and.awt.Color
  105. * @see and.awt.Graphics#getColor
  106. */
  107. public void setColor(Color c) {
  108. setPaint(c);
  109. }
  110. /**
  111. * Returns the current <code>Stroke</code> in the
  112. * <code>Graphics2D</code> context.
  113. * @return the current <code>Graphics2D</code> <code>Stroke</code>,
  114. * which defines the line style.
  115. * @see #setStroke
  116. */
  117. public Stroke getStroke(){
  118. return _stroke;
  119. }
  120. /**
  121. * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  122. * @param s the <code>Stroke</code> object to be used to stroke a
  123. * <code>Shape</code> during the rendering process
  124. */
  125. public void setStroke(Stroke s){
  126. this._stroke = s;
  127. }
  128. /**
  129. * Returns the current <code>Paint</code> of the
  130. * <code>Graphics2D</code> context.
  131. * @return the current <code>Graphics2D</code> <code>Paint</code>,
  132. * which defines a color or pattern.
  133. * @see #setPaint
  134. * @see and.awt.Graphics#setColor
  135. */
  136. public Paint getPaint(){
  137. return _paint;
  138. }
  139. /**
  140. * Sets the <code>Paint</code> attribute for the
  141. * <code>Graphics2D</code> context. Calling this method
  142. * with a <code>null</code> <code>Paint</code> object does
  143. * not have any effect on the current <code>Paint</code> attribute
  144. * of this <code>Graphics2D</code>.
  145. * @param paint the <code>Paint</code> object to be used to generate
  146. * color during the rendering process, or <code>null</code>
  147. * @see and.awt.Graphics#setColor
  148. */
  149. public void setPaint(Paint paint){
  150. if(paint == null) return;
  151. this._paint = paint;
  152. if (paint instanceof Color) _foreground = (Color)paint;
  153. }
  154. /**
  155. * Returns a copy of the current <code>Transform</code> in the
  156. * <code>Graphics2D</code> context.
  157. * @return the current <code>AffineTransform</code> in the
  158. * <code>Graphics2D</code> context.
  159. * @see #_transform
  160. * @see #setTransform
  161. */
  162. public AffineTransform getTransform(){
  163. return new AffineTransform(_transform);
  164. }
  165. /**
  166. * Sets the <code>Transform</code> in the <code>Graphics2D</code>
  167. * context.
  168. * @param Tx the <code>AffineTransform</code> object to be used in the
  169. * rendering process
  170. * @see #_transform
  171. * @see AffineTransform
  172. */
  173. public void setTransform(AffineTransform Tx) {
  174. _transform = new AffineTransform(Tx);
  175. }
  176. /**
  177. * Strokes the outline of a <code>Shape</code> using the settings of the
  178. * current <code>Graphics2D</code> context. The rendering attributes
  179. * applied include the <code>Clip</code>, <code>Transform</code>,
  180. * <code>Paint</code>, <code>Composite</code> and
  181. * <code>Stroke</code> attributes.
  182. * @param shape the <code>Shape</code> to be rendered
  183. * @see #setStroke
  184. * @see #setPaint
  185. * @see and.awt.Graphics#setColor
  186. * @see #_transform
  187. * @see #setTransform
  188. * @see #clip
  189. * @see #setClip
  190. * @see #setComposite
  191. */
  192. public void draw(Shape shape){
  193. GeneralPath path = new GeneralPath(_transform.createTransformedShape(shape));
  194. Freeform p = new Freeform(_group);
  195. p.setPath(path);
  196. p.getFill().setForegroundColor(null);
  197. applyStroke(p);
  198. _group.addShape(p);
  199. }
  200. /**
  201. * Renders the text specified by the specified <code>String</code>,
  202. * using the current text attribute state in the <code>Graphics2D</code> context.
  203. * The baseline of the first character is at position
  204. * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
  205. * The rendering attributes applied include the <code>Clip</code>,
  206. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  207. * <code>Composite</code> attributes. For characters in script systems
  208. * such as Hebrew and Arabic, the glyphs can be rendered from right to
  209. * left, in which case the coordinate supplied is the location of the
  210. * leftmost character on the baseline.
  211. * @param s the <code>String</code> to be rendered
  212. * @param x the x coordinate of the location where the
  213. * <code>String</code> should be rendered
  214. * @param y the y coordinate of the location where the
  215. * <code>String</code> should be rendered
  216. * @throws NullPointerException if <code>str</code> is
  217. * <code>null</code>
  218. * @see #setPaint
  219. * @see and.awt.Graphics#setColor
  220. * @see and.awt.Graphics#setFont
  221. * @see #setTransform
  222. * @see #setComposite
  223. * @see #setClip
  224. */
  225. public void drawString(String s, float x, float y) {
  226. TextBox txt = new TextBox(_group);
  227. txt.getTextRun().supplySlideShow(_group.getSheet().getSlideShow());
  228. txt.getTextRun().setSheet(_group.getSheet());
  229. txt.setText(s);
  230. RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
  231. rt.setFontSize(_font.getSize());
  232. rt.setFontName(_font.getFamily());
  233. if (getColor() != null) rt.setFontColor(getColor());
  234. if (_font.isBold()) rt.setBold(true);
  235. if (_font.isItalic()) rt.setItalic(true);
  236. txt.setMarginBottom(0);
  237. txt.setMarginTop(0);
  238. txt.setMarginLeft(0);
  239. txt.setMarginRight(0);
  240. txt.setWordWrap(TextBox.WrapNone);
  241. txt.setHorizontalAlignment(TextBox.AlignLeft);
  242. txt.setVerticalAlignment(TextBox.AnchorMiddle);
  243. TextLayout layout = new TextLayout(s, _font, getFontRenderContext());
  244. float ascent = layout.getAscent();
  245. float width = (float) Math.floor(layout.getAdvance());
  246. /**
  247. * Even if top and bottom margins are set to 0 PowerPoint
  248. * always sets extra space between the text and its bounding box.
  249. *
  250. * The approximation height = ascent*2 works good enough in most cases
  251. */
  252. float height = ascent * 2;
  253. /*
  254. In powerpoint anchor of a shape is its top left corner.
  255. Java graphics sets string coordinates by the baseline of the first character
  256. so we need to shift up by the height of the textbox
  257. */
  258. y -= height / 2 + ascent / 2;
  259. /*
  260. In powerpoint anchor of a shape is its top left corner.
  261. Java graphics sets string coordinates by the baseline of the first character
  262. so we need to shift down by the height of the textbox
  263. */
  264. txt.setAnchor(new Rectangle2D.Float(x, y, width, height));
  265. _group.addShape(txt);
  266. }
  267. /**
  268. * Fills the interior of a <code>Shape</code> using the settings of the
  269. * <code>Graphics2D</code> context. The rendering attributes applied
  270. * include the <code>Clip</code>, <code>Transform</code>,
  271. * <code>Paint</code>, and <code>Composite</code>.
  272. * @param shape the <code>Shape</code> to be filled
  273. * @see #setPaint
  274. * @see and.awt.Graphics#setColor
  275. * @see #_transform
  276. * @see #setTransform
  277. * @see #setComposite
  278. * @see #clip
  279. * @see #setClip
  280. */
  281. public void fill(Shape shape){
  282. GeneralPath path = new GeneralPath(_transform.createTransformedShape(shape));
  283. Freeform p = new Freeform(_group);
  284. p.setPath(path);
  285. applyPaint(p);
  286. p.setLineColor(null); //Fills must be "No Line"
  287. _group.addShape(p);
  288. }
  289. /**
  290. * Translates the origin of the graphics context to the point
  291. * (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
  292. * Modifies this graphics context so that its new origin corresponds
  293. * to the point (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's
  294. * original coordinate system. All coordinates used in subsequent
  295. * rendering operations on this graphics context will be relative
  296. * to this new origin.
  297. * @param x the <i>x</i> coordinate.
  298. * @param y the <i>y</i> coordinate.
  299. */
  300. public void translate(int x, int y){
  301. _transform.translate(x, y);
  302. }
  303. /**
  304. * Intersects the current <code>Clip</code> with the interior of the
  305. * specified <code>Shape</code> and sets the <code>Clip</code> to the
  306. * resulting intersection. The specified <code>Shape</code> is
  307. * transformed with the current <code>Graphics2D</code>
  308. * <code>Transform</code> before being intersected with the current
  309. * <code>Clip</code>. This method is used to make the current
  310. * <code>Clip</code> smaller.
  311. * To make the <code>Clip</code> larger, use <code>setClip</code>.
  312. * The <i>user clip</i> modified by this method is independent of the
  313. * clipping associated with device bounds and visibility. If no clip has
  314. * previously been set, or if the clip has been cleared using
  315. * {@link and.awt.Graphics#setClip(Shape) setClip} with a
  316. * <code>null</code> argument, the specified <code>Shape</code> becomes
  317. * the new user clip.
  318. * @param s the <code>Shape</code> to be intersected with the current
  319. * <code>Clip</code>. If <code>s</code> is <code>null</code>,
  320. * this method clears the current <code>Clip</code>.
  321. */
  322. public void clip(Shape s){
  323. log.log(POILogger.WARN, "Not implemented");
  324. }
  325. /**
  326. * Gets the current clipping area.
  327. * This method returns the user clip, which is independent of the
  328. * clipping associated with device bounds and window visibility.
  329. * If no clip has previously been set, or if the clip has been
  330. * cleared using <code>setClip(null)</code>, this method returns
  331. * <code>null</code>.
  332. * @return a <code>Shape</code> object representing the
  333. * current clipping area, or <code>null</code> if
  334. * no clip is set.
  335. * @see and.awt.Graphics#getClipBounds()
  336. * @see and.awt.Graphics#clipRect
  337. * @see and.awt.Graphics#setClip(int, int, int, int)
  338. * @see and.awt.Graphics#setClip(Shape)
  339. * @since JDK1.1
  340. */
  341. public Shape getClip(){
  342. log.log(POILogger.WARN, "Not implemented");
  343. return null;
  344. }
  345. /**
  346. * Concatenates the current <code>Graphics2D</code>
  347. * <code>Transform</code> with a scaling transformation
  348. * Subsequent rendering is resized according to the specified scaling
  349. * factors relative to the previous scaling.
  350. * This is equivalent to calling <code>transform(S)</code>, where S is an
  351. * <code>AffineTransform</code> represented by the following matrix:
  352. * <pre>
  353. * [ sx 0 0 ]
  354. * [ 0 sy 0 ]
  355. * [ 0 0 1 ]
  356. * </pre>
  357. * @param sx the amount by which X coordinates in subsequent
  358. * rendering operations are multiplied relative to previous
  359. * rendering operations.
  360. * @param sy the amount by which Y coordinates in subsequent
  361. * rendering operations are multiplied relative to previous
  362. * rendering operations.
  363. */
  364. public void scale(double sx, double sy){
  365. _transform.scale(sx, sy);
  366. }
  367. /**
  368. * Draws an outlined round-cornered rectangle using this graphics
  369. * context's current color. The left and right edges of the rectangle
  370. * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
  371. * respectively. The top and bottom edges of the rectangle are at
  372. * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
  373. * @param x the <i>x</i> coordinate of the rectangle to be drawn.
  374. * @param y the <i>y</i> coordinate of the rectangle to be drawn.
  375. * @param width the width of the rectangle to be drawn.
  376. * @param height the height of the rectangle to be drawn.
  377. * @param arcWidth the horizontal diameter of the arc
  378. * at the four corners.
  379. * @param arcHeight the vertical diameter of the arc
  380. * at the four corners.
  381. * @see and.awt.Graphics#fillRoundRect
  382. */
  383. public void drawRoundRect(int x, int y, int width, int height,
  384. int arcWidth, int arcHeight){
  385. RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight);
  386. draw(rect);
  387. }
  388. /**
  389. * Draws the text given by the specified string, using this
  390. * graphics context's current font and color. The baseline of the
  391. * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
  392. * graphics context's coordinate system.
  393. * @param str the string to be drawn.
  394. * @param x the <i>x</i> coordinate.
  395. * @param y the <i>y</i> coordinate.
  396. * @see and.awt.Graphics#drawBytes
  397. * @see and.awt.Graphics#drawChars
  398. */
  399. public void drawString(String str, int x, int y){
  400. drawString(str, (float)x, (float)y);
  401. }
  402. /**
  403. * Fills an oval bounded by the specified rectangle with the
  404. * current color.
  405. * @param x the <i>x</i> coordinate of the upper left corner
  406. * of the oval to be filled.
  407. * @param y the <i>y</i> coordinate of the upper left corner
  408. * of the oval to be filled.
  409. * @param width the width of the oval to be filled.
  410. * @param height the height of the oval to be filled.
  411. * @see and.awt.Graphics#drawOval
  412. */
  413. public void fillOval(int x, int y, int width, int height){
  414. Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
  415. fill(oval);
  416. }
  417. /**
  418. * Fills the specified rounded corner rectangle with the current color.
  419. * The left and right edges of the rectangle
  420. * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
  421. * respectively. The top and bottom edges of the rectangle are at
  422. * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
  423. * @param x the <i>x</i> coordinate of the rectangle to be filled.
  424. * @param y the <i>y</i> coordinate of the rectangle to be filled.
  425. * @param width the width of the rectangle to be filled.
  426. * @param height the height of the rectangle to be filled.
  427. * @param arcWidth the horizontal diameter
  428. * of the arc at the four corners.
  429. * @param arcHeight the vertical diameter
  430. * of the arc at the four corners.
  431. * @see and.awt.Graphics#drawRoundRect
  432. */
  433. public void fillRoundRect(int x, int y, int width, int height,
  434. int arcWidth, int arcHeight){
  435. RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight);
  436. fill(rect);
  437. }
  438. /**
  439. * Fills a circular or elliptical arc covering the specified rectangle.
  440. * <p>
  441. * The resulting arc begins at <code>startAngle</code> and extends
  442. * for <code>arcAngle</code> degrees.
  443. * Angles are interpreted such that 0&nbsp;degrees
  444. * is at the 3&nbsp;o'clock position.
  445. * A positive value indicates a counter-clockwise rotation
  446. * while a negative value indicates a clockwise rotation.
  447. * <p>
  448. * The center of the arc is the center of the rectangle whose origin
  449. * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
  450. * <code>width</code> and <code>height</code> arguments.
  451. * <p>
  452. * The resulting arc covers an area
  453. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  454. * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
  455. * <p>
  456. * The angles are specified relative to the non-square extents of
  457. * the bounding rectangle such that 45 degrees always falls on the
  458. * line from the center of the ellipse to the upper right corner of
  459. * the bounding rectangle. As a result, if the bounding rectangle is
  460. * noticeably longer in one axis than the other, the angles to the
  461. * start and end of the arc segment will be skewed farther along the
  462. * longer axis of the bounds.
  463. * @param x the <i>x</i> coordinate of the
  464. * upper-left corner of the arc to be filled.
  465. * @param y the <i>y</i> coordinate of the
  466. * upper-left corner of the arc to be filled.
  467. * @param width the width of the arc to be filled.
  468. * @param height the height of the arc to be filled.
  469. * @param startAngle the beginning angle.
  470. * @param arcAngle the angular extent of the arc,
  471. * relative to the start angle.
  472. * @see and.awt.Graphics#drawArc
  473. */
  474. public void fillArc(int x, int y, int width, int height,
  475. int startAngle, int arcAngle){
  476. Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
  477. fill(arc);
  478. }
  479. /**
  480. * Draws the outline of a circular or elliptical arc
  481. * covering the specified rectangle.
  482. * <p>
  483. * The resulting arc begins at <code>startAngle</code> and extends
  484. * for <code>arcAngle</code> degrees, using the current color.
  485. * Angles are interpreted such that 0&nbsp;degrees
  486. * is at the 3&nbsp;o'clock position.
  487. * A positive value indicates a counter-clockwise rotation
  488. * while a negative value indicates a clockwise rotation.
  489. * <p>
  490. * The center of the arc is the center of the rectangle whose origin
  491. * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
  492. * <code>width</code> and <code>height</code> arguments.
  493. * <p>
  494. * The resulting arc covers an area
  495. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  496. * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
  497. * <p>
  498. * The angles are specified relative to the non-square extents of
  499. * the bounding rectangle such that 45 degrees always falls on the
  500. * line from the center of the ellipse to the upper right corner of
  501. * the bounding rectangle. As a result, if the bounding rectangle is
  502. * noticeably longer in one axis than the other, the angles to the
  503. * start and end of the arc segment will be skewed farther along the
  504. * longer axis of the bounds.
  505. * @param x the <i>x</i> coordinate of the
  506. * upper-left corner of the arc to be drawn.
  507. * @param y the <i>y</i> coordinate of the
  508. * upper-left corner of the arc to be drawn.
  509. * @param width the width of the arc to be drawn.
  510. * @param height the height of the arc to be drawn.
  511. * @param startAngle the beginning angle.
  512. * @param arcAngle the angular extent of the arc,
  513. * relative to the start angle.
  514. * @see and.awt.Graphics#fillArc
  515. */
  516. public void drawArc(int x, int y, int width, int height,
  517. int startAngle, int arcAngle) {
  518. Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
  519. draw(arc);
  520. }
  521. /**
  522. * Draws a sequence of connected lines defined by
  523. * arrays of <i>x</i> and <i>y</i> coordinates.
  524. * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
  525. * The figure is not closed if the first point
  526. * differs from the last point.
  527. * @param xPoints an array of <i>x</i> points
  528. * @param yPoints an array of <i>y</i> points
  529. * @param nPoints the total number of points
  530. * @see and.awt.Graphics#drawPolygon(int[], int[], int)
  531. * @since JDK1.1
  532. */
  533. public void drawPolyline(int[] xPoints, int[] yPoints,
  534. int nPoints){
  535. if(nPoints > 0){
  536. GeneralPath path = new GeneralPath();
  537. path.moveTo(xPoints[0], yPoints[0]);
  538. for(int i=1; i<nPoints; i++)
  539. path.lineTo(xPoints[i], yPoints[i]);
  540. draw(path);
  541. }
  542. }
  543. /**
  544. * Draws the outline of an oval.
  545. * The result is a circle or ellipse that fits within the
  546. * rectangle specified by the <code>x</code>, <code>y</code>,
  547. * <code>width</code>, and <code>height</code> arguments.
  548. * <p>
  549. * The oval covers an area that is
  550. * <code>width&nbsp;+&nbsp;1</code> pixels wide
  551. * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
  552. * @param x the <i>x</i> coordinate of the upper left
  553. * corner of the oval to be drawn.
  554. * @param y the <i>y</i> coordinate of the upper left
  555. * corner of the oval to be drawn.
  556. * @param width the width of the oval to be drawn.
  557. * @param height the height of the oval to be drawn.
  558. * @see and.awt.Graphics#fillOval
  559. */
  560. public void drawOval(int x, int y, int width, int height){
  561. Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
  562. draw(oval);
  563. }
  564. /**
  565. * Draws as much of the specified image as is currently available.
  566. * The image is drawn with its top-left corner at
  567. * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
  568. * space. Transparent pixels are drawn in the specified
  569. * background color.
  570. * <p>
  571. * This operation is equivalent to filling a rectangle of the
  572. * width and height of the specified image with the given color and then
  573. * drawing the image on top of it, but possibly more efficient.
  574. * <p>
  575. * This method returns immediately in all cases, even if the
  576. * complete image has not yet been loaded, and it has not been dithered
  577. * and converted for the current output device.
  578. * <p>
  579. * If the image has not yet been completely loaded, then
  580. * <code>drawImage</code> returns <code>false</code>. As more of
  581. * the image becomes available, the process that draws the image notifies
  582. * the specified image observer.
  583. * @param img the specified image to be drawn.
  584. * @param x the <i>x</i> coordinate.
  585. * @param y the <i>y</i> coordinate.
  586. * @param bgcolor the background color to paint under the
  587. * non-opaque portions of the image.
  588. * @param observer object to be notified as more of
  589. * the image is converted.
  590. * @see and.awt.Image
  591. * @see and.awt.image.ImageObserver
  592. * @see and.awt.image.ImageObserver#imageUpdate(and.awt.Image, int, int, int, int, int)
  593. */
  594. public boolean drawImage(Image img, int x, int y,
  595. Color bgcolor,
  596. ImageObserver observer){
  597. log.log(POILogger.WARN, "Not implemented");
  598. return false;
  599. }
  600. /**
  601. * Draws as much of the specified image as has already been scaled
  602. * to fit inside the specified rectangle.
  603. * <p>
  604. * The image is drawn inside the specified rectangle of this
  605. * graphics context's coordinate space, and is scaled if
  606. * necessary. Transparent pixels are drawn in the specified
  607. * background color.
  608. * This operation is equivalent to filling a rectangle of the
  609. * width and height of the specified image with the given color and then
  610. * drawing the image on top of it, but possibly more efficient.
  611. * <p>
  612. * This method returns immediately in all cases, even if the
  613. * entire image has not yet been scaled, dithered, and converted
  614. * for the current output device.
  615. * If the current output representation is not yet complete then
  616. * <code>drawImage</code> returns <code>false</code>. As more of
  617. * the image becomes available, the process that draws the image notifies
  618. * the specified image observer.
  619. * <p>
  620. * A scaled version of an image will not necessarily be
  621. * available immediately just because an unscaled version of the
  622. * image has been constructed for this output device. Each size of
  623. * the image may be cached separately and generated from the original
  624. * data in a separate image production sequence.
  625. * @param img the specified image to be drawn.
  626. * @param x the <i>x</i> coordinate.
  627. * @param y the <i>y</i> coordinate.
  628. * @param width the width of the rectangle.
  629. * @param height the height of the rectangle.
  630. * @param bgcolor the background color to paint under the
  631. * non-opaque portions of the image.
  632. * @param observer object to be notified as more of
  633. * the image is converted.
  634. * @see and.awt.Image
  635. * @see and.awt.image.ImageObserver
  636. * @see and.awt.image.ImageObserver#imageUpdate(and.awt.Image, int, int, int, int, int)
  637. */
  638. public boolean drawImage(Image img, int x, int y,
  639. int width, int height,
  640. Color bgcolor,
  641. ImageObserver observer){
  642. log.log(POILogger.WARN, "Not implemented");
  643. return false;
  644. }
  645. /**
  646. * Draws as much of the specified area of the specified image as is
  647. * currently available, scaling it on the fly to fit inside the
  648. * specified area of the destination drawable surface. Transparent pixels
  649. * do not affect whatever pixels are already there.
  650. * <p>
  651. * This method returns immediately in all cases, even if the
  652. * image area to be drawn has not yet been scaled, dithered, and converted
  653. * for the current output device.
  654. * If the current output representation is not yet complete then
  655. * <code>drawImage</code> returns <code>false</code>. As more of
  656. * the image becomes available, the process that draws the image notifies
  657. * the specified image observer.
  658. * <p>
  659. * This method always uses the unscaled version of the image
  660. * to render the scaled rectangle and performs the required
  661. * scaling on the fly. It does not use a cached, scaled version
  662. * of the image for this operation. Scaling of the image from source
  663. * to destination is performed such that the first coordinate
  664. * of the source rectangle is mapped to the first coordinate of
  665. * the destination rectangle, and the second source coordinate is
  666. * mapped to the second destination coordinate. The subimage is
  667. * scaled and flipped as needed to preserve those mappings.
  668. * @param img the specified image to be drawn
  669. * @param dx1 the <i>x</i> coordinate of the first corner of the
  670. * destination rectangle.
  671. * @param dy1 the <i>y</i> coordinate of the first corner of the
  672. * destination rectangle.
  673. * @param dx2 the <i>x</i> coordinate of the second corner of the
  674. * destination rectangle.
  675. * @param dy2 the <i>y</i> coordinate of the second corner of the
  676. * destination rectangle.
  677. * @param sx1 the <i>x</i> coordinate of the first corner of the
  678. * source rectangle.
  679. * @param sy1 the <i>y</i> coordinate of the first corner of the
  680. * source rectangle.
  681. * @param sx2 the <i>x</i> coordinate of the second corner of the
  682. * source rectangle.
  683. * @param sy2 the <i>y</i> coordinate of the second corner of the
  684. * source rectangle.
  685. * @param observer object to be notified as more of the image is
  686. * scaled and converted.
  687. * @see and.awt.Image
  688. * @see and.awt.image.ImageObserver
  689. * @see and.awt.image.ImageObserver#imageUpdate(and.awt.Image, int, int, int, int, int)
  690. * @since JDK1.1
  691. */
  692. public boolean drawImage(Image img,
  693. int dx1, int dy1, int dx2, int dy2,
  694. int sx1, int sy1, int sx2, int sy2,
  695. ImageObserver observer){
  696. log.log(POILogger.WARN, "Not implemented");
  697. return false;
  698. }
  699. /**
  700. * Draws as much of the specified area of the specified image as is
  701. * currently available, scaling it on the fly to fit inside the
  702. * specified area of the destination drawable surface.
  703. * <p>
  704. * Transparent pixels are drawn in the specified background color.
  705. * This operation is equivalent to filling a rectangle of the
  706. * width and height of the specified image with the given color and then
  707. * drawing the image on top of it, but possibly more efficient.
  708. * <p>
  709. * This method returns immediately in all cases, even if the
  710. * image area to be drawn has not yet been scaled, dithered, and converted
  711. * for the current output device.
  712. * If the current output representation is not yet complete then
  713. * <code>drawImage</code> returns <code>false</code>. As more of
  714. * the image becomes available, the process that draws the image notifies
  715. * the specified image observer.
  716. * <p>
  717. * This method always uses the unscaled version of the image
  718. * to render the scaled rectangle and performs the required
  719. * scaling on the fly. It does not use a cached, scaled version
  720. * of the image for this operation. Scaling of the image from source
  721. * to destination is performed such that the first coordinate
  722. * of the source rectangle is mapped to the first coordinate of
  723. * the destination rectangle, and the second source coordinate is
  724. * mapped to the second destination coordinate. The subimage is
  725. * scaled and flipped as needed to preserve those mappings.
  726. * @param img the specified image to be drawn
  727. * @param dx1 the <i>x</i> coordinate of the first corner of the
  728. * destination rectangle.
  729. * @param dy1 the <i>y</i> coordinate of the first corner of the
  730. * destination rectangle.
  731. * @param dx2 the <i>x</i> coordinate of the second corner of the
  732. * destination rectangle.
  733. * @param dy2 the <i>y</i> coordinate of the second corner of the
  734. * destination rectangle.
  735. * @param sx1 the <i>x</i> coordinate of the first corner of the
  736. * source rectangle.
  737. * @param sy1 the <i>y</i> coordinate of the first corner of the
  738. * source rectangle.
  739. * @param sx2 the <i>x</i> coordinate of the second corner of the
  740. * source rectangle.
  741. * @param sy2 the <i>y</i> coordinate of the second corner of the
  742. * source rectangle.
  743. * @param bgcolor the background color to paint under the
  744. * non-opaque portions of the image.
  745. * @param observer object to be notified as more of the image is
  746. * scaled and converted.
  747. * @see and.awt.Image
  748. * @see and.awt.image.ImageObserver
  749. * @see and.awt.image.ImageObserver#imageUpdate(and.awt.Image, int, int, int, int, int)
  750. * @since JDK1.1
  751. */
  752. public boolean drawImage(Image img,
  753. int dx1, int dy1, int dx2, int dy2,
  754. int sx1, int sy1, int sx2, int sy2,
  755. Color bgcolor,
  756. ImageObserver observer){
  757. log.log(POILogger.WARN, "Not implemented");
  758. return false;
  759. }
  760. /**
  761. * Draws as much of the specified image as is currently available.
  762. * The image is drawn with its top-left corner at
  763. * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
  764. * space. Transparent pixels in the image do not affect whatever
  765. * pixels are already there.
  766. * <p>
  767. * This method returns immediately in all cases, even if the
  768. * complete image has not yet been loaded, and it has not been dithered
  769. * and converted for the current output device.
  770. * <p>
  771. * If the image has completely loaded and its pixels are
  772. * no longer being changed, then
  773. * <code>drawImage</code> returns <code>true</code>.
  774. * Otherwise, <code>drawImage</code> returns <code>false</code>
  775. * and as more of
  776. * the image becomes available
  777. * or it is time to draw another frame of animation,
  778. * the process that loads the image notifies
  779. * the specified image observer.
  780. * @param img the specified image to be drawn. This method does
  781. * nothing if <code>img</code> is null.
  782. * @param x the <i>x</i> coordinate.
  783. * @param y the <i>y</i> coordinate.
  784. * @param observer object to be notified as more of
  785. * the image is converted.
  786. * @return <code>false</code> if the image pixels are still changing;
  787. * <code>true</code> otherwise.
  788. * @see and.awt.Image
  789. * @see and.awt.image.ImageObserver
  790. * @see and.awt.image.ImageObserver#imageUpdate(and.awt.Image, int, int, int, int, int)
  791. */
  792. public boolean drawImage(Image img, int x, int y,
  793. ImageObserver observer) {
  794. log.log(POILogger.WARN, "Not implemented");
  795. return false;
  796. }
  797. /**
  798. * Disposes of this graphics context and releases
  799. * any system resources that it is using.
  800. * A <code>Graphics</code> object cannot be used after
  801. * <code>dispose</code>has been called.
  802. * <p>
  803. * When a Java program runs, a large number of <code>Graphics</code>
  804. * objects can be created within a short time frame.
  805. * Although the finalization process of the garbage collector
  806. * also disposes of the same system resources, it is preferable
  807. * to manually free the associated resources by calling this
  808. * method rather than to rely on a finalization process which
  809. * may not run to completion for a long period of time.
  810. * <p>
  811. * Graphics objects which are provided as arguments to the
  812. * <code>paint</code> and <code>update</code> methods
  813. * of components are automatically released by the system when
  814. * those methods return. For efficiency, programmers should
  815. * call <code>dispose</code> when finished using
  816. * a <code>Graphics</code> object only if it was created
  817. * directly from a component or another <code>Graphics</code> object.
  818. * @see and.awt.Graphics#finalize
  819. * @see and.awt.Component#paint
  820. * @see and.awt.Component#update
  821. * @see and.awt.Component#getGraphics
  822. * @see and.awt.Graphics#create
  823. */
  824. public void dispose() {
  825. ;
  826. }
  827. /**
  828. * Draws a line, using the current color, between the points
  829. * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
  830. * in this graphics context's coordinate system.
  831. * @param x1 the first point's <i>x</i> coordinate.
  832. * @param y1 the first point's <i>y</i> coordinate.
  833. * @param x2 the second point's <i>x</i> coordinate.
  834. * @param y2 the second point's <i>y</i> coordinate.
  835. */
  836. public void drawLine(int x1, int y1, int x2, int y2){
  837. Line2D line = new Line2D.Float(x1, y1, x2, y2);
  838. draw(line);
  839. }
  840. /**
  841. * Fills a closed polygon defined by
  842. * arrays of <i>x</i> and <i>y</i> coordinates.
  843. * <p>
  844. * This method draws the polygon defined by <code>nPoint</code> line
  845. * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
  846. * line segments are line segments from
  847. * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
  848. * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
  849. * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
  850. * The figure is automatically closed by drawing a line connecting
  851. * the final point to the first point, if those points are different.
  852. * <p>
  853. * The area inside the polygon is defined using an
  854. * even-odd fill rule, also known as the alternating rule.
  855. * @param xPoints a an array of <code>x</code> coordinates.
  856. * @param yPoints a an array of <code>y</code> coordinates.
  857. * @param nPoints a the total number of points.
  858. * @see and.awt.Graphics#drawPolygon(int[], int[], int)
  859. */
  860. public void fillPolygon(int[] xPoints, int[] yPoints,
  861. int nPoints){
  862. and.awt.Polygon polygon = new and.awt.Polygon(xPoints, yPoints, nPoints);
  863. fill(polygon);
  864. }
  865. /**
  866. * Fills the specified rectangle.
  867. * The left and right edges of the rectangle are at
  868. * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
  869. * The top and bottom edges are at
  870. * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
  871. * The resulting rectangle covers an area
  872. * <code>width</code> pixels wide by
  873. * <code>height</code> pixels tall.
  874. * The rectangle is filled using the graphics context's current color.
  875. * @param x the <i>x</i> coordinate
  876. * of the rectangle to be filled.
  877. * @param y the <i>y</i> coordinate
  878. * of the rectangle to be filled.
  879. * @param width the width of the rectangle to be filled.
  880. * @param height the height of the rectangle to be filled.
  881. * @see and.awt.Graphics#clearRect
  882. * @see and.awt.Graphics#drawRect
  883. */
  884. public void fillRect(int x, int y, int width, int height){
  885. Rectangle rect = new Rectangle(x, y, width, height);
  886. fill(rect);
  887. }
  888. /**
  889. * Draws the outline of the specified rectangle.
  890. * The left and right edges of the rectangle are at
  891. * <code>x</code> and <code>x&nbsp;+&nbsp;width</code>.
  892. * The top and bottom edges are at
  893. * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
  894. * The rectangle is drawn using the graphics context's current color.
  895. * @param x the <i>x</i> coordinate
  896. * of the rectangle to be drawn.
  897. * @param y the <i>y</i> coordinate
  898. * of the rectangle to be drawn.
  899. * @param width the width of the rectangle to be drawn.
  900. * @param height the height of the rectangle to be drawn.
  901. * @see and.awt.Graphics#fillRect
  902. * @see and.awt.Graphics#clearRect
  903. */
  904. public void drawRect(int x, int y, int width, int height) {
  905. Rectangle rect = new Rectangle(x, y, width, height);
  906. draw(rect);
  907. }
  908. /**
  909. * Draws a closed polygon defined by
  910. * arrays of <i>x</i> and <i>y</i> coordinates.
  911. * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
  912. * <p>
  913. * This method draws the polygon defined by <code>nPoint</code> line
  914. * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
  915. * line segments are line segments from
  916. * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
  917. * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
  918. * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
  919. * The figure is automatically closed by drawing a line connecting
  920. * the final point to the first point, if those points are different.
  921. * @param xPoints a an array of <code>x</code> coordinates.
  922. * @param yPoints a an array of <code>y</code> coordinates.
  923. * @param nPoints a the total number of points.
  924. * @see and.awt.Graphics#fillPolygon(int[],int[],int)
  925. * @see and.awt.Graphics#drawPolyline
  926. */
  927. public void drawPolygon(int[] xPoints, int[] yPoints,
  928. int nPoints){
  929. and.awt.Polygon polygon = new and.awt.Polygon(xPoints, yPoints, nPoints);
  930. draw(polygon);
  931. }
  932. /**
  933. * Intersects the current clip with the specified rectangle.
  934. * The resulting clipping area is the intersection of the current
  935. * clipping area and the specified rectangle. If there is no
  936. * current clipping area, either because the clip has never been
  937. * set, or the clip has been cleared using <code>setClip(null)</code>,
  938. * the specified rectangle becomes the new clip.
  939. * This method sets the user clip, which is independent of the
  940. * clipping associated with device bounds and window visibility.
  941. * This method can only be used to make the current clip smaller.
  942. * To set the current clip larger, use any of the setClip methods.
  943. * Rendering operations have no effect outside of the clipping area.
  944. * @param x the x coordinate of the rectangle to intersect the clip with
  945. * @param y the y coordinate of the rectangle to intersect the clip with
  946. * @param width the width of the rectangle to intersect the clip with
  947. * @param height the height of the rectangle to intersect the clip with
  948. * @see #setClip(int, int, int, int)
  949. * @see #setClip(Shape)
  950. */
  951. public void clipRect(int x, int y, int width, int height){
  952. clip(new Rectangle(x, y, width, height));
  953. }
  954. /**
  955. * Sets the current clipping area to an arbitrary clip shape.
  956. * Not all objects that implement the <code>Shape</code>
  957. * interface can be used to set the clip. The only
  958. * <code>Shape</code> objects that are guaranteed to be
  959. * supported are <code>Shape</code> objects that are
  960. * obtained via the <code>getClip</code> method and via
  961. * <code>Rectangle</code> objects. This method sets the
  962. * user clip, which is independent of the clipping associated
  963. * with device bounds and window visibility.
  964. * @param clip the <code>Shape</code> to use to set the clip
  965. * @see and.awt.Graphics#getClip()
  966. * @see and.awt.Graphics#clipRect
  967. * @see and.awt.Graphics#setClip(int, int, int, int)
  968. * @since JDK1.1
  969. */
  970. public void setClip(Shape clip) {
  971. log.log(POILogger.WARN, "Not implemented");
  972. }
  973. /**
  974. * Returns the bounding rectangle of the current clipping area.
  975. * This method refers to the user clip, which is independent of the
  976. * clipping associated with device bounds and window visibility.
  977. * If no clip has previously been set, or if the clip has been
  978. * cleared using <code>setClip(null)</code>, this method returns
  979. * <code>null</code>.
  980. * The coordinates in the rectangle are relative to the coordinate
  981. * system origin of this graphics context.
  982. * @return the bounding rectangle of the current clipping area,
  983. * or <code>null</code> if no clip is set.
  984. * @see and.awt.Graphics#getClip
  985. * @see and.awt.Graphics#clipRect
  986. * @see and.awt.Graphics#setClip(int, int, int, int)
  987. * @see and.awt.Graphics#setClip(Shape)
  988. * @since JDK1.1
  989. */
  990. public Rectangle getClipBounds(){
  991. Shape c = getClip();
  992. if (c==null) {
  993. return null;
  994. }
  995. return c.getBounds();
  996. }
  997. /**
  998. * Draws the text given by the specified iterator, using this
  999. * graphics context's current color. The iterator has to specify a font
  1000. * for each character. The baseline of the
  1001. * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
  1002. * graphics context's coordinate system.
  1003. * @param iterator the iterator whose text is to be drawn
  1004. * @param x the <i>x</i> coordinate.
  1005. * @param y the <i>y</i> coordinate.
  1006. * @see and.awt.Graphics#drawBytes
  1007. * @see and.awt.Graphics#drawChars
  1008. */
  1009. public void drawString(AttributedCharacterIterator iterator,
  1010. int x, int y){
  1011. drawString(iterator, (float)x, (float)y);
  1012. }
  1013. /**
  1014. * Clears the specified rectangle by filling it with the background
  1015. * color of the current drawing surface. This operation does not
  1016. * use the current paint mode.
  1017. * <p>
  1018. * Beginning with Java&nbsp;1.1, the background color
  1019. * of offscreen images may be system dependent. Applications should
  1020. * use <code>setColor</code> followed by <code>fillRect</code> to
  1021. * ensure that an offscreen image is cleared to a specific color.
  1022. * @param x the <i>x</i> coordinate of the rectangle to clear.
  1023. * @param y the <i>y</i> coordinate of the rectangle to clear.
  1024. * @param width the width of the rectangle to clear.
  1025. * @param height the height of the rectangle to clear.
  1026. * @see and.awt.Graphics#fillRect(int, int, int, int)
  1027. * @see and.awt.Graphics#drawRect
  1028. * @see and.awt.Graphics#setColor(and.awt.Color)
  1029. * @see and.awt.Graphics#setPaintMode
  1030. * @see and.awt.Graphics#setXORMode(and.awt.Color)
  1031. */
  1032. public void clearRect(int x, int y, int width, int height) {
  1033. Paint paint = getPaint();
  1034. setColor(getBackground());
  1035. fillRect(x, y, width, height);
  1036. setPaint(paint);
  1037. }
  1038. public void copyArea(int x, int y, int width, int height, int dx, int dy) {
  1039. ;
  1040. }
  1041. /**
  1042. * Sets the current clip to the rectangle specified by the given
  1043. * coordinates. This method sets the user clip, which is
  1044. * independent of the clipping associated with device bounds
  1045. * and window visibility.
  1046. * Rendering operations have no effect outside of the clipping area.
  1047. * @param x the <i>x</i> coordinate of the new clip rectangle.
  1048. * @param y the <i>y</i> coordinate of the new clip rectangle.
  1049. * @param width the width of the new clip rectangle.
  1050. * @param height the height of the new clip rectangle.
  1051. * @see and.awt.Graphics#clipRect
  1052. * @see and.awt.Graphics#setClip(Shape)
  1053. * @since JDK1.1
  1054. */
  1055. public void setClip(int x, int y, int width, int height){
  1056. setClip(new Rectangle(x, y, width, height));
  1057. }
  1058. /**
  1059. * Concatenates the current <code>Graphics2D</code>
  1060. * <code>Transform</code> with a rotation transform.
  1061. * Subs…

Large files files are truncated, but you can click here to view the full file