Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LineRenderer.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.textpane;
  18. import java.awt.Graphics2D;
  19. import java.awt.font.TextLayout;
  20. import java.awt.geom.Rectangle2D;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. /**
  24. * Renders a single line in a document to a graphics object.
  25. */
  26. public interface LineRenderer {
  27. /**
  28. * Renders a line to the given graphics object.
  29. *
  30. * @param graphics The graphics object to render to.
  31. * @param canvasWidth The width of the canvas available to render on.
  32. * @param canvasHeight The height of the canvas available to render on.
  33. * @param drawPosY The Y position to start rendering at.
  34. * @param line The number of the line to be rendered.
  35. * @return The result of the render. Callers should not store the result object, as it may
  36. * be recycled.
  37. */
  38. RenderResult render(final Graphics2D graphics, final float canvasWidth,
  39. final float canvasHeight, final float drawPosY, final int line);
  40. /**
  41. * Describes the results of a rendering attempt.
  42. *
  43. * <p>For performance purposes, renderers should create a single instance of this class and
  44. * recycle it between calls to {@link #render}. Callers should copy the values they require
  45. * out of the result before calling {@link #render} again.
  46. */
  47. class RenderResult {
  48. /** Map of line information to their rendered rectangles. */
  49. public final Map<LineInfo, Rectangle2D.Float> drawnAreas = new HashMap<>();
  50. /** Map of line information to the layout used to render them. */
  51. public final Map<LineInfo, TextLayout> textLayouts = new HashMap<>();
  52. /** The total height that was used while rendering, in pixels. */
  53. public float totalHeight;
  54. /** The ID of the first visible line that was rendered. */
  55. public int firstVisibleLine;
  56. }
  57. }