BorderedLayoutPosition.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package epson.print.phlayout;
  2. import android.content.Context;
  3. import android.graphics.Point;
  4. import android.graphics.Rect;
  5. import android.graphics.RectF;
  6. import android.support.annotation.NonNull;
  7. import epson.common.Info_paper;
  8. import epson.print.EPImage;
  9. public class BorderedLayoutPosition implements ILayoutPosition {
  10. private int layout = 2;
  11. private int layoutMulti = 0;
  12. private int m3mmHeight = 0;
  13. private int m3mmWidth = 0;
  14. private int mBottomMargin = 0;
  15. private boolean mIsPaperLandScape = false;
  16. private int mLeftMargin = 0;
  17. private AltRect mPreview3mmEffectivePrintPosition = new AltRect();
  18. private int[] mPreviewMargin = new int[4];
  19. private int mRightMargin = 0;
  20. private int mTopMargin = 0;
  21. /* access modifiers changed from: package-private */
  22. @VisibleForTesting
  23. public AltRect getPreviewPaperAltRect() {
  24. return null;
  25. }
  26. public Rect getPreviewPaperRect() {
  27. return null;
  28. }
  29. public int getLayoutId() {
  30. return this.layout;
  31. }
  32. public int getLeftMargin() {
  33. return this.mPreviewMargin[0];
  34. }
  35. public int getRightMargin() {
  36. return this.mPreviewMargin[2];
  37. }
  38. public int getTopMargin() {
  39. return this.mPreviewMargin[1];
  40. }
  41. public int getBottomMargin() {
  42. return this.mPreviewMargin[3];
  43. }
  44. public int[] getPrintSize(Context context, int i, int i2) {
  45. setLayoutId(2, i2);
  46. setPaperSizeFromPaperInfo(Info_paper.getInfoPaper(context, i));
  47. return new int[]{this.m3mmWidth, this.m3mmHeight};
  48. }
  49. public RectF getPreviewImageCircumscribedTargetSize() {
  50. return this.mPreview3mmEffectivePrintPosition.getRectF();
  51. }
  52. public boolean isPreviewImageSizeValid() {
  53. return this.mPreview3mmEffectivePrintPosition.right - this.mPreview3mmEffectivePrintPosition.left > 0 && this.mPreview3mmEffectivePrintPosition.bottom - this.mPreview3mmEffectivePrintPosition.top > 0;
  54. }
  55. public void setPaperLandscape(boolean z) {
  56. this.mIsPaperLandScape = z;
  57. }
  58. public boolean getIsPaperLandscape() {
  59. return this.mIsPaperLandScape;
  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.m3mmWidth = i3;
  65. this.m3mmHeight = i4;
  66. }
  67. public void setLayoutId(int i, int i2) {
  68. this.layout = i;
  69. this.layoutMulti = i2;
  70. }
  71. public void setPaperAndCalcPreviewPosition(Info_paper info_paper, int i, int i2, Point point) {
  72. int i3 = this.layout;
  73. setPaperSizeFromPaperInfo(info_paper);
  74. if (this.m3mmWidth <= 0 || this.m3mmHeight <= 0) {
  75. this.m3mmWidth = 2892;
  76. this.m3mmHeight = 4125;
  77. }
  78. calculateLayoutSizeBordered(i, i2, point);
  79. }
  80. /* access modifiers changed from: package-private */
  81. @VisibleForTesting
  82. public void calculateLayoutSizeBordered(int i, int i2, Point point) {
  83. int i3;
  84. int i4;
  85. if ((!this.mIsPaperLandScape || this.m3mmWidth > this.m3mmHeight) && (this.mIsPaperLandScape || this.m3mmWidth <= this.m3mmHeight)) {
  86. i3 = (int) (((double) i2) * 0.800000011920929d);
  87. int i5 = this.m3mmWidth;
  88. int i6 = this.m3mmHeight;
  89. int i7 = (int) (((float) (i3 * i5)) / ((float) i6));
  90. int i8 = (int) (((double) i) * 0.800000011920929d);
  91. if (i7 > i8) {
  92. i3 = (int) (((float) (i6 * i8)) / ((float) i5));
  93. i4 = i8;
  94. } else {
  95. i4 = i7;
  96. }
  97. } else {
  98. i4 = (int) (((double) i) * 0.800000011920929d);
  99. int i9 = this.m3mmWidth;
  100. int i10 = this.m3mmHeight;
  101. i3 = (int) (((float) (i4 * i9)) / ((float) i10));
  102. int i11 = (int) (((double) i2) * 0.800000011920929d);
  103. if (i3 > i11) {
  104. i4 = (int) (((float) (i10 * i11)) / ((float) i9));
  105. i3 = i11;
  106. }
  107. }
  108. AltRect altRect = this.mPreview3mmEffectivePrintPosition;
  109. altRect.left = (i - i4) / 2;
  110. altRect.top = (i2 - i3) / 2;
  111. altRect.right = altRect.left + i4;
  112. AltRect altRect2 = this.mPreview3mmEffectivePrintPosition;
  113. altRect2.bottom = altRect2.top + i3;
  114. point.x = ((this.mPreview3mmEffectivePrintPosition.right - this.mPreview3mmEffectivePrintPosition.left) / 2) + this.mPreview3mmEffectivePrintPosition.left;
  115. point.y = ((this.mPreview3mmEffectivePrintPosition.bottom - this.mPreview3mmEffectivePrintPosition.top) / 2) + this.mPreview3mmEffectivePrintPosition.top;
  116. float width = ((float) this.mPreview3mmEffectivePrintPosition.width()) / ((float) this.m3mmWidth);
  117. int[] iArr = this.mPreviewMargin;
  118. iArr[0] = (int) (((float) this.mLeftMargin) * width);
  119. iArr[1] = (int) (((float) this.mTopMargin) * width);
  120. iArr[2] = (int) (((float) this.mRightMargin) * width);
  121. iArr[3] = (int) (((float) this.mBottomMargin) * width);
  122. if (this.mIsPaperLandScape) {
  123. int i12 = iArr[1];
  124. iArr[1] = iArr[2];
  125. iArr[2] = iArr[3];
  126. iArr[3] = iArr[0];
  127. iArr[0] = i12;
  128. }
  129. }
  130. /* access modifiers changed from: package-private */
  131. @VisibleForTesting
  132. public void setPaperSizeFromPaperInfo(Info_paper info_paper) {
  133. if (this.layout == 2) {
  134. this.m3mmWidth = info_paper.getPaper_width_boder();
  135. this.m3mmHeight = info_paper.getPaper_height_boder();
  136. this.mLeftMargin = info_paper.getLeftMargin_border();
  137. this.mTopMargin = info_paper.getTopMargin_border();
  138. this.mRightMargin = info_paper.getRightMargin_border();
  139. this.mBottomMargin = info_paper.getBottomMargin_border();
  140. int i = this.layoutMulti;
  141. if (i == 65536) {
  142. Rect printingArea_2in1 = info_paper.getPrintingArea_2in1();
  143. this.m3mmWidth = printingArea_2in1.width();
  144. this.m3mmHeight = printingArea_2in1.height();
  145. } else if (i == 131072 || i == 262144) {
  146. Rect printingArea_4in1 = info_paper.getPrintingArea_4in1();
  147. this.m3mmWidth = printingArea_4in1.width();
  148. this.m3mmHeight = printingArea_4in1.height();
  149. }
  150. } else {
  151. throw new RuntimeException();
  152. }
  153. }
  154. public void copyPreviewPrintAreaFromEpImage(@NonNull EPImage ePImage) {
  155. this.mIsPaperLandScape = ePImage.isPaperLandScape;
  156. this.mPreview3mmEffectivePrintPosition.left = ePImage.previewPaperRectLeft;
  157. this.mPreview3mmEffectivePrintPosition.top = ePImage.previewPaperRectTop;
  158. this.mPreview3mmEffectivePrintPosition.right = ePImage.previewPaperRectRight;
  159. this.mPreview3mmEffectivePrintPosition.bottom = ePImage.previewPaperRectBottom;
  160. }
  161. public void copyPreviewPrintAreaToEpImage(EPImage ePImage) {
  162. ePImage.isPaperLandScape = this.mIsPaperLandScape;
  163. ePImage.previewPaperRectLeft = this.mPreview3mmEffectivePrintPosition.left;
  164. ePImage.previewPaperRectTop = this.mPreview3mmEffectivePrintPosition.top;
  165. ePImage.previewPaperRectRight = this.mPreview3mmEffectivePrintPosition.right;
  166. ePImage.previewPaperRectBottom = this.mPreview3mmEffectivePrintPosition.bottom;
  167. }
  168. }