TextBlock.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.luooqi.ocr.model;
  2. import java.awt.Point;
  3. public class TextBlock {
  4. private Point topLeft;
  5. private Point topRight;
  6. private Point bottomLeft;
  7. private Point bottomRight;
  8. private double angle;
  9. private double fontSize;
  10. private String text;
  11. public TextBlock(){}
  12. public TextBlock(Point topLeft, Point topRight, Point bottomLeft, Point bottomRight, String text) {
  13. this.topLeft = topLeft;
  14. this.topRight = topRight;
  15. this.bottomLeft = bottomLeft;
  16. this.bottomRight = bottomRight;
  17. this.text = text;
  18. calcAngle();
  19. }
  20. public Point getTopLeft() {
  21. return topLeft;
  22. }
  23. public void setTopLeft(Point topLeft) {
  24. this.topLeft = topLeft;
  25. calcAngle();
  26. }
  27. public Point getTopRight() {
  28. return topRight;
  29. }
  30. public void setTopRight(Point topRight) {
  31. this.topRight = topRight;
  32. calcAngle();
  33. }
  34. public Point getBottomLeft() {
  35. return bottomLeft;
  36. }
  37. public void setBottomLeft(Point bottomLeft) {
  38. this.bottomLeft = bottomLeft;
  39. calcAngle();
  40. }
  41. public Point getBottomRight() {
  42. return bottomRight;
  43. }
  44. public void setBottomRight(Point bottomRight) {
  45. this.bottomRight = bottomRight;
  46. calcAngle();
  47. }
  48. public String getText() {
  49. return text;
  50. }
  51. public void setText(String text) {
  52. this.text = text;
  53. }
  54. public double getFontSize() {
  55. return fontSize;
  56. }
  57. private void setFontSize(double fontSize) {
  58. this.fontSize = fontSize;
  59. }
  60. private void calcAngle() {
  61. if (this.topLeft != null && this.bottomLeft != null) {
  62. int x = this.topLeft.x - this.bottomLeft.x;
  63. int y = this.bottomLeft.y - this.topLeft.y;
  64. setAngle(x * 1.0 / y);
  65. setFontSize(Math.sqrt(x * x + y * y));
  66. }
  67. }
  68. public double getAngle() {
  69. return angle;
  70. }
  71. private void setAngle(double angle) {
  72. this.angle = angle;
  73. }
  74. }