/src/main/java/com/extentech/formats/XLS/charts/CrtLayout12.java

https://bitbucket.org/giovanniroos/openxls · Java · 144 lines · 37 code · 6 blank · 101 comment · 3 complexity · cdb7c7b4d0a3f5803c0be1df1deef772 MD5 · raw file

  1. /*
  2. * --------- BEGIN COPYRIGHT NOTICE ---------
  3. * Copyright 2002-2012 Extentech Inc.
  4. * Copyright 2013 Infoteria America Corp.
  5. *
  6. * This file is part of OpenXLS.
  7. *
  8. * OpenXLS is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as
  10. * published by the Free Software Foundation, either version 3 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * OpenXLS is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with OpenXLS. If not, see
  20. * <http://www.gnu.org/licenses/>.
  21. * ---------- END COPYRIGHT NOTICE ----------
  22. */
  23. package com.extentech.formats.XLS.charts;
  24. import com.extentech.toolkit.ByteTools;
  25. /**
  26. * The CrtLayout12 record specifies the layout information for attached label
  27. * (data label or legend)
  28. * 12 frtHeader 0x89D
  29. * 4 dwCheckSum : An unsigned integer that specifies the checksum of the values in the order as follows, if the checksum is incorrect,
  30. * the layout information specified in this record MUST be ignored.
  31. Checksum for type Values
  32. AttachedLabel x1 field of the Pos record in the sequence of records that contains this CrtLayout12 record and conforms to the ATTACHEDLABEL rule.
  33. y1 field of the Pos record in the in the sequence of records that contains this CrtLayout12 record and conforms to the ATTACHEDLABEL rule.
  34. An unsigned integer that specifies whether the attached label is at its default position. MUST be 1 if the dlp field of the Text record in the in the sequence of records that contains this CrtLayout12 record and conforms to the ATTACHEDLABEL rule is equal to 0xA. Otherwise, MUST be zero.
  35. Legend x1 field of the Pos record in the in the sequence of records that contains this CrtLayout12 record and conforms to the LD rule.
  36. y1 field of the Pos record in the in the sequence of records that contains this CrtLayout12 record and conforms to the LD rule.
  37. Width of the legend in pixels.
  38. Height of the legend in pixels.
  39. The fAutoPosX field of Legend record.
  40. The fAutoPosY field of Legend record.
  41. The fAutoSize of the Frame record in the in the sequence of records that contains this CrtLayout12 record and conforms to the LD rule.
  42. The width and height of legend in pixels are calculated with the following steps:
  43. Get chart area width in pixels
  44. chart area width in pixels = (dx field of Chart record - 8) * DPI of the display device / 72
  45. If the frt field of the Frame record following the Chart record is 0x0004 and the chart is not embedded, add the shadow size:
  46. chart area width in pixels -= 2 * line width of the display device in pixels
  47. Get chart area height in pixels
  48. chart area height in pixels = (dy field of Chart record - 8) * DPI of the display device / 72
  49. If the frt field of the Frame record following the Chart record is 0x0004 and the chart is not embedded, add the shadow size:
  50. chart area height in pixels -= 2 * line height of the display device in pixels
  51. Compute legend size in pixels
  52. legend width in pixels = dx field of Legend / 4000 * chart area width in pixels
  53. legend height in pixels = dy field of Legend / 4000 * chart area height in pixels
  54. 2 1 bit- unused
  55. autolayouttype (4 bits): An unsigned integer that specifies the automatic layout type of the legend.
  56. MUST be ignored when this record is in the sequence of records that conforms to the ATTACHEDLABEL rule.
  57. MUST be a value from the following table:
  58. Value Meaning
  59. 0x0 Align to the bottom
  60. 0x1 Align to top right corner
  61. 0x2 Align to the top
  62. 0x3 Align to the right
  63. 0x4 Align to the left
  64. reserved1 (11 bits): MUST be zero, and MUST be ignored.
  65. 2 wXMode A CrtLayout12Mode structure that specifies the meaning of x.
  66. 2 wYMode A CrtLayout12Mode structure that specifies the meaning of y.
  67. 2 wWidthMode A CrtLayout12Mode structure that specifies the meaning of dx.
  68. 2 wHeightMode A CrtLayout12Mode structure that specifies the meaning of dy.
  69. 8 x (8 bytes): An Xnum value that specifies a horizontal offset. The meaning is determined by wXMode.
  70. 8 y (8 bytes): An Xnum value that specifies a vertical offset. The meaning is determined by wYMode.
  71. 8 dx (8 bytes): An Xnum value that specifies a width or an horizontal offset. The meaning is determined by wWidthMode.
  72. 8 dy (8 bytes): An Xnum value that specifies a height or an vertical offset. The meaning is determined by wHeightMode.
  73. 2 reserved2 (2 bytes): MUST be zero, and MUST be ignored.
  74. *
  75. */
  76. public class CrtLayout12 extends GenericChartObject implements ChartObject {
  77. byte autolayouttype;
  78. short wXMode, wYMode;
  79. short wWidthMode, wHeightMode;
  80. float x, y, dx, dy;
  81. public void init() {
  82. super.init();
  83. byte[] data= this.getData();
  84. autolayouttype= (byte)(data[16] >> 1);
  85. wXMode= ByteTools.readShort(data[18], data[19]);
  86. wYMode= ByteTools.readShort(data[20], data[21]);
  87. wWidthMode= ByteTools.readShort(data[22], data[23]);
  88. wHeightMode= ByteTools.readShort(data[24], data[25]);
  89. x= (float)ByteTools.eightBytetoLEDouble(this.getBytesAt(26, 8));
  90. y= (float)ByteTools.eightBytetoLEDouble(this.getBytesAt(34, 8));
  91. dx= (float)ByteTools.eightBytetoLEDouble(this.getBytesAt(42, 8));
  92. dy= (float)ByteTools.eightBytetoLEDouble(this.getBytesAt(50, 8));
  93. }
  94. /**
  95. * returns the legend autolayout type:
  96. * <br>
  97. 0x0 Align to the bottom
  98. 0x1 Align to top right corner
  99. 0x2 Align to the top
  100. 0x3 Align to the right
  101. 0x4 Align to the left
  102. * @return
  103. */
  104. public int getLayout() {
  105. return autolayouttype;
  106. }
  107. /**
  108. * sets the layout position of the attached legend or attached label
  109. * * <br>
  110. 0x0 Align to the bottom
  111. 0x1 Align to top right corner
  112. 0x2 Align to the top
  113. 0x3 Align to the right
  114. 0x4 Align to the left
  115. * @param pos
  116. */
  117. public void setLayout(int pos) {
  118. autolayouttype= (byte) pos;
  119. this.getData()[16]= (byte)(autolayouttype << 1);
  120. }
  121. public float[] getCoords() {
  122. /* return new float[] { Pos.convertFromSPRC(xTL, w, 0), // x offset
  123. Pos.convertFromSPRC(yTL, 0, h), // y offset
  124. Pos.convertFromSPRC(xBR, w, 0), // w
  125. Pos.convertFromSPRC(yBR, 0, h) }; // h
  126. */
  127. if (wWidthMode==0) {
  128. return null;
  129. }
  130. if (wWidthMode==1) {
  131. //x and y specify the offset of the top left corner, relative to its default position, as a fraction of the chart area. MUST be greater than or equal to -1.0 and MUST be less than or equal to 1.0. dx and dy specify the width and height, as a fraction of the chart area, MUST be greater than or equal to 0.0, and MUST be less than or equal to 1.0.
  132. } if (wWidthMode==2) {
  133. // x and y specify the offset of the upper-left corner; dx and dy specify the offset of the bottom-right corner. x, y, dx and dy are specified relative to the upper-left corner of the chart area as a fraction of the chart area. x, y, dx and dy MUST be greater than or equal to 0.0, and MUST be less than or equal to 1.0.
  134. }
  135. return null;
  136. }
  137. }