BorderlessLayoutPosition.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package epson.print.phlayout;
  2. import android.graphics.Point;
  3. import android.graphics.Rect;
  4. import android.graphics.RectF;
  5. import android.support.annotation.NonNull;
  6. import epson.common.Info_paper;
  7. import epson.print.EPImage;
  8. class BorderlessLayoutPosition implements ILayoutPosition {
  9. private int layout = 2;
  10. private int layoutMulti = 0;
  11. private int[] mBorderlessPrintArea = new int[2];
  12. private int mBottomMargin = 0;
  13. private boolean mIsPaperLandScape = false;
  14. private int mLeftMargin = 0;
  15. private int mPaperHeight = 0;
  16. private int mPaperWidth = 0;
  17. private AltRect mPreviewPaperRect = new AltRect();
  18. private AltRectF mPreviewPrintAreaRect = new AltRectF();
  19. private int mRightMargin = 0;
  20. private int mTopMargin = 0;
  21. BorderlessLayoutPosition() {
  22. }
  23. public int getLayoutId() {
  24. return this.layout;
  25. }
  26. public int getLeftMargin() {
  27. return (int) (((float) this.mPreviewPaperRect.left) - this.mPreviewPrintAreaRect.left);
  28. }
  29. public int getRightMargin() {
  30. return (int) (this.mPreviewPrintAreaRect.right - ((float) this.mPreviewPaperRect.right));
  31. }
  32. public int getTopMargin() {
  33. return (int) (((float) this.mPreviewPaperRect.top) - this.mPreviewPrintAreaRect.top);
  34. }
  35. public int getBottomMargin() {
  36. return (int) (this.mPreviewPrintAreaRect.bottom - ((float) this.mPreviewPaperRect.bottom));
  37. }
  38. public RectF getPreviewImageCircumscribedTargetSize() {
  39. return this.mPreviewPrintAreaRect.getRectF();
  40. }
  41. public boolean isPreviewImageSizeValid() {
  42. return this.mPreviewPaperRect.right - this.mPreviewPaperRect.left > 0 && this.mPreviewPaperRect.bottom - this.mPreviewPaperRect.top > 0;
  43. }
  44. private AltRectF getPreviewImageAltRect() {
  45. return this.mPreviewPrintAreaRect;
  46. }
  47. public void setPaperLandscape(boolean z) {
  48. this.mIsPaperLandScape = z;
  49. }
  50. public boolean getIsPaperLandscape() {
  51. return this.mIsPaperLandScape;
  52. }
  53. public Rect getPreviewPaperRect() {
  54. return this.mPreviewPaperRect.getRect();
  55. }
  56. /* access modifiers changed from: package-private */
  57. @VisibleForTesting
  58. public AltRect getPreviewPaperAltRect() {
  59. return this.mPreviewPaperRect;
  60. }
  61. /* access modifiers changed from: package-private */
  62. @VisibleForTesting
  63. public void setPaperAndImageSize_forTest(int i, int i2, int i3, int i4) {
  64. this.mPaperWidth = i;
  65. this.mPaperHeight = i2;
  66. int[] iArr = this.mBorderlessPrintArea;
  67. iArr[0] = i3;
  68. iArr[1] = i4;
  69. }
  70. /* access modifiers changed from: package-private */
  71. @VisibleForTesting
  72. public void setMargin_forTest(int[] iArr) {
  73. this.mLeftMargin = iArr[0];
  74. this.mTopMargin = iArr[1];
  75. this.mRightMargin = iArr[2];
  76. this.mBottomMargin = iArr[3];
  77. }
  78. public void setLayoutId(int i, int i2) {
  79. this.layout = i;
  80. this.layoutMulti = i2;
  81. }
  82. public void setPaperAndCalcPreviewPosition(Info_paper info_paper, int i, int i2, Point point) {
  83. setPaperSizeFromPaperInfo(info_paper);
  84. if (this.mPaperWidth <= 0 || this.mPaperHeight <= 0) {
  85. this.mPaperWidth = 2892;
  86. this.mPaperHeight = 4125;
  87. }
  88. calculateLayoutSizeBorderless(i, i2, point);
  89. }
  90. /* access modifiers changed from: package-private */
  91. @VisibleForTesting
  92. public void calculateLayoutSizeBorderless(int i, int i2, Point point) {
  93. int i3;
  94. int i4;
  95. int i5;
  96. int i6;
  97. int i7;
  98. int i8 = i;
  99. int i9 = i2;
  100. Point point2 = point;
  101. int[] iArr = new int[4];
  102. if ((!this.mIsPaperLandScape || this.mPaperWidth > this.mPaperHeight) && (this.mIsPaperLandScape || this.mPaperWidth <= this.mPaperHeight)) {
  103. int i10 = (int) (((double) i9) * 0.800000011920929d);
  104. int i11 = this.mPaperWidth;
  105. int i12 = this.mPaperHeight;
  106. int i13 = (int) (((float) (i10 * i11)) / ((float) i12));
  107. int[] iArr2 = this.mBorderlessPrintArea;
  108. int i14 = (int) (((float) (iArr2[0] * i13)) / ((float) i11));
  109. int i15 = (int) (((float) (iArr2[1] * i10)) / ((float) i12));
  110. int i16 = (int) (((double) i8) * 0.800000011920929d);
  111. if (i13 > i16) {
  112. int i17 = (int) (((float) (i16 * i12)) / ((float) i11));
  113. i6 = (int) (((float) (iArr2[0] * i16)) / ((float) i11));
  114. i5 = (int) (((float) (iArr2[1] * i17)) / ((float) i12));
  115. i3 = i17;
  116. i7 = i16;
  117. } else {
  118. i6 = i14;
  119. int i18 = i15;
  120. i3 = i10;
  121. i7 = i13;
  122. i5 = i18;
  123. }
  124. float f = ((float) i3) / ((float) this.mPaperHeight);
  125. iArr[0] = (int) (((float) this.mLeftMargin) * f);
  126. iArr[1] = (int) (((float) this.mTopMargin) * f);
  127. i4 = 2;
  128. iArr[2] = (int) (((float) this.mRightMargin) * f);
  129. iArr[3] = (int) (((float) this.mBottomMargin) * f);
  130. } else {
  131. int i19 = (int) (((double) i8) * 0.800000011920929d);
  132. int i20 = this.mPaperWidth;
  133. int i21 = this.mPaperHeight;
  134. int i22 = (int) (((float) (i19 * i20)) / ((float) i21));
  135. int[] iArr3 = this.mBorderlessPrintArea;
  136. int i23 = (int) (((float) (i19 * iArr3[1])) / ((float) i21));
  137. int i24 = (int) (((float) (iArr3[0] * i22)) / ((float) i20));
  138. int i25 = (int) (((double) i9) * 0.800000011920929d);
  139. if (i22 > i25) {
  140. i19 = (int) (((float) (i25 * i21)) / ((float) i20));
  141. i23 = (int) (((float) (iArr3[1] * i19)) / ((float) i21));
  142. i24 = (int) (((float) (iArr3[0] * i25)) / ((float) i20));
  143. i22 = i25;
  144. }
  145. float f2 = ((float) i7) / ((float) this.mPaperHeight);
  146. iArr[0] = (int) (((float) this.mTopMargin) * f2);
  147. iArr[1] = (int) (((float) this.mRightMargin) * f2);
  148. iArr[2] = (int) (((float) this.mBottomMargin) * f2);
  149. iArr[3] = (int) (((float) this.mLeftMargin) * f2);
  150. i4 = 2;
  151. }
  152. AltRect altRect = this.mPreviewPaperRect;
  153. altRect.left = (i8 - i7) / i4;
  154. altRect.top = (i9 - i3) / i4;
  155. altRect.right = altRect.left + i7;
  156. AltRect altRect2 = this.mPreviewPaperRect;
  157. altRect2.bottom = altRect2.top + i3;
  158. this.mPreviewPrintAreaRect = new AltRectF();
  159. this.mPreviewPrintAreaRect.left = (float) (this.mPreviewPaperRect.left - iArr[0]);
  160. this.mPreviewPrintAreaRect.top = (float) (this.mPreviewPaperRect.top - iArr[1]);
  161. AltRectF altRectF = this.mPreviewPrintAreaRect;
  162. altRectF.right = altRectF.left + ((float) i6);
  163. AltRectF altRectF2 = this.mPreviewPrintAreaRect;
  164. altRectF2.bottom = altRectF2.top + ((float) i5);
  165. point2.x = (int) (((this.mPreviewPrintAreaRect.right - this.mPreviewPrintAreaRect.left) / 2.0f) + this.mPreviewPrintAreaRect.left);
  166. point2.y = (int) (((this.mPreviewPrintAreaRect.bottom - this.mPreviewPrintAreaRect.top) / 2.0f) + this.mPreviewPrintAreaRect.top);
  167. }
  168. /* access modifiers changed from: package-private */
  169. @VisibleForTesting
  170. public void setPaperSizeFromPaperInfo(Info_paper info_paper) {
  171. this.mPaperWidth = info_paper.getPaper_width();
  172. this.mPaperHeight = info_paper.getPaper_height();
  173. this.mBorderlessPrintArea[0] = info_paper.getPaper_width_boderless();
  174. this.mBorderlessPrintArea[1] = info_paper.getPaper_height_boderless();
  175. this.mLeftMargin = -info_paper.getLeftMargin();
  176. this.mTopMargin = -info_paper.getTopMargin();
  177. this.mRightMargin = -info_paper.getRightMargin();
  178. this.mBottomMargin = -info_paper.getBottomMargin();
  179. }
  180. public void copyPreviewPrintAreaFromEpImage(@NonNull EPImage ePImage) {
  181. this.mIsPaperLandScape = ePImage.isPaperLandScape;
  182. this.mPreviewPrintAreaRect.left = (float) ePImage.previewPaperRectLeft;
  183. this.mPreviewPrintAreaRect.top = (float) ePImage.previewPaperRectTop;
  184. this.mPreviewPrintAreaRect.right = (float) ePImage.previewPaperRectRight;
  185. this.mPreviewPrintAreaRect.bottom = (float) ePImage.previewPaperRectBottom;
  186. }
  187. public void copyPreviewPrintAreaToEpImage(EPImage ePImage) {
  188. ePImage.isPaperLandScape = this.mIsPaperLandScape;
  189. ePImage.previewPaperRectLeft = (int) this.mPreviewPrintAreaRect.left;
  190. ePImage.previewPaperRectTop = (int) this.mPreviewPrintAreaRect.top;
  191. ePImage.previewPaperRectRight = (int) this.mPreviewPrintAreaRect.right;
  192. ePImage.previewPaperRectBottom = (int) this.mPreviewPrintAreaRect.bottom;
  193. }
  194. }