*/
public static final int POINT_DPI = 72;
+
+ /**
+ * Width of one "standard character" of the default font in pixels. Same for Calibri and Arial.
+ * "Standard character" defined as the widest digit character in the given font.
+ * Copied from XSSFWorkbook, since that isn't available here.
+ * <p/>
+ * Note this is only valid for workbooks using the default Excel font.
+ * <p/>
+ * Would be nice to eventually support arbitrary document default fonts.
+ */
+ public static final float DEFAULT_CHARACTER_WIDTH = 7.0017f;
+
+ /**
+ * Column widths are in fractional characters, this is the EMU equivalent.
+ * One character is defined as the widest value for the integers 0-9 in the
+ * default font.
+ */
+ public static final int EMU_PER_CHARACTER = (int) (EMU_PER_PIXEL * DEFAULT_CHARACTER_WIDTH);
+
/**
* Converts points to EMUs
* @param points points
points /= PIXEL_DPI;
return points;
}
+
+ public static int charactersToEMU(double characters) {
+ return (int) characters * EMU_PER_CHARACTER;
+ }
+
+ /**
+ * @param columnWidth specified in 256ths of a standard character
+ * @return equivalent EMUs
+ */
+ public static int columnWidthToEMU(int columnWidth) {
+ return charactersToEMU(columnWidth / 256d);
+ }
+
+ /**
+ * @param twips (1/20th of a point) typically used for row heights
+ * @return equivalent EMUs
+ */
+ public static int TwipsToEMU(short twips) {
+ return (int) (twips / 20d * EMU_PER_POINT);
+ }
}
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
import org.apache.poi.xssf.usermodel.XSSFAnchor;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFPictureData;
-import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
assert (w > scaledWidth);
double cw = getColumnWidthInPixels(col2);
double deltaW = w - scaledWidth;
- int dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - deltaW));
+ int dx2 = (int)(Units.EMU_PER_PIXEL * (cw - deltaW));
anchor.setCol2(col2);
anchor.setDx2(dx2);
assert (h > scaledHeight);
double ch = getRowHeightInPixels(row2);
double deltaH = h - scaledHeight;
- int dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - deltaH));
+ int dy2 = (int)(Units.EMU_PER_PIXEL * (ch - deltaH));
anchor.setRow2(row2);
anchor.setDy2(dy2);
CTPositiveSize2D size2d = getCTPicture().getSpPr().getXfrm().getExt();
- size2d.setCx((long)(scaledWidth * XSSFShape.EMU_PER_PIXEL));
- size2d.setCy((long)(scaledHeight * XSSFShape.EMU_PER_PIXEL));
+ size2d.setCx((long)(scaledWidth * Units.EMU_PER_PIXEL));
+ size2d.setCy((long)(scaledHeight * Units.EMU_PER_PIXEL));
return anchor;
}
CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false);
double numChars = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
- return (float)numChars*XSSFWorkbook.DEFAULT_CHARACTER_WIDTH;
+ return (float)numChars*Units.DEFAULT_CHARACTER_WIDTH;
}
private float getRowHeightInPixels(int rowIndex) {
SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet);
Row row = sheet.getRow(rowIndex);
float height = row != null ? row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints();
- return height * XSSFShape.PIXEL_DPI / XSSFShape.POINT_DPI;
+ return height * Units.PIXEL_DPI / Units.POINT_DPI;
}
/**
* Return the dimension of this image
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
-import org.apache.poi.xssf.util.EMUUtils;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
int r = cell.getRow();
int c = cell.getCol();
- int cw = EMUUtils.EMUsFromColumnWidth(sheet.getColumnWidth(c));
+ int cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
// start with width - offset, then keep adding column widths until the next one puts us over w
long wPos = cw - cell.getColOff();
while (wPos < w) {
c++;
- cw = EMUUtils.EMUsFromColumnWidth(sheet.getColumnWidth(c));
+ cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
wPos += cw;
}
// now wPos >= w, so end column = c, now figure offset
c2.setCol(c);
c2.setColOff(cw - (wPos - w));
- int rh = EMUUtils.EMUsFromPoints(getRowHeight(sheet, r));
+ int rh = Units.toEMU(getRowHeight(sheet, r));
// start with height - offset, then keep adding row heights until the next one puts us over h
long hPos = rh - cell.getRowOff();
while (hPos < h) {
r++;
- rh = EMUUtils.EMUsFromPoints(getRowHeight(sheet, r));
+ rh = Units.toEMU(getRowHeight(sheet, r));
hPos += rh;
}
// now hPos >= h, so end row = r, now figure offset
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.Shape;
+import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;
* Represents a shape in a SpreadsheetML drawing.
*/
public abstract class XSSFShape implements Shape {
- public static final int EMU_PER_PIXEL = 9525;
- public static final int EMU_PER_POINT = 12700;
+ /**
+ * @deprecated POI 3.17 beta 1
+ * @see Units#EMU_PER_PIXEL
+ */
+ @Removal(version="3.19")
+ public static final int EMU_PER_PIXEL = Units.EMU_PER_PIXEL;
+
+ /**
+ * @deprecated POI 3.17 beta 1
+ * @see Units#EMU_PER_POINT
+ */
+ @Removal(version="3.19")
+ public static final int EMU_PER_POINT = Units.EMU_PER_POINT;
- public static final int POINT_DPI = 72;
- public static final int PIXEL_DPI = 96;
+ /**
+ * @deprecated POI 3.17 beta 1
+ * @see Units#POINT_DPI
+ */
+ @Removal(version="3.19")
+ public static final int POINT_DPI = Units.POINT_DPI;
+
+ /**
+ * @deprecated POI 3.17 beta 1
+ * @see Units#PIXEL_DPI
+ */
+ @Removal(version="3.19")
+ public static final int PIXEL_DPI = Units.PIXEL_DPI;
/**
* Parent drawing
public void setLineWidth( double lineWidth ) {
CTShapeProperties props = getShapeProperties();
CTLineProperties ln = props.isSetLn() ? props.getLn() : props.addNewLn();
- ln.setW((int)(lineWidth*EMU_PER_POINT));
+ ln.setW((int)(lineWidth*Units.EMU_PER_POINT));
}
/**
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
@Override
public float getColumnWidthInPixels(int columnIndex) {
float widthIn256 = getColumnWidth(columnIndex);
- return (float)(widthIn256/256.0*XSSFWorkbook.DEFAULT_CHARACTER_WIDTH);
+ return (float)(widthIn256/256.0*Units.DEFAULT_CHARACTER_WIDTH);
}
/**
import org.apache.poi.util.POILogger;
import org.apache.poi.util.PackageHelper;
import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
import org.apache.poi.xssf.XLSBUnsupportedException;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.model.ExternalLinksTable;
/**
* Width of one character of the default font in pixels. Same for Calibry and Arial.
+ * @deprecated POI 3.17 beta 1
+ * @see Units#DEFAULT_CHARACTER_WIDTH
*/
- public static final float DEFAULT_CHARACTER_WIDTH = 7.0017f;
+ @Removal(version="3.19")
+ public static final float DEFAULT_CHARACTER_WIDTH = Units.DEFAULT_CHARACTER_WIDTH;
/**
* Excel silently truncates long sheet names to 31 chars.
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.xssf.util;
-
-import org.apache.poi.xssf.usermodel.XSSFShape;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
-/**
- * Conversion methods for OOXML EMU values - "English Metric Units" or more accurately
- * "Evil Measurement Units".
- * <p/>
- * These are defined briefly in <a href="https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML">Wikipedia</a>
- * as a "rational" way to use an integer value to represent something that could be in
- * inches, centimeters, points, or pixels.
- * So now we get to convert between all those.
- */
-public class EMUUtils {
- public static final int EMUS_PER_INCH = 914400;
- public static final int EMUS_PER_POINT = 12700;
- public static final int EMUS_PER_CENTIMETER = 360000;
-
- // TODO: these could move here or something to standardize definitions
- public static final int EMU_PER_PIXEL = XSSFShape.EMU_PER_PIXEL;
- public static final int EMU_PER_POINT = XSSFShape.EMU_PER_POINT;
- public static final int PIXEL_DPI = XSSFShape.PIXEL_DPI;
- public static final int POINT_DPI = XSSFShape.POINT_DPI;
- public static final int EMU_PER_CHARACTER = (int) (EMU_PER_PIXEL * XSSFWorkbook.DEFAULT_CHARACTER_WIDTH);
-
- /**
- * @param columnWidth as (fractional # of characters) * 256
- * @return EMUs
- */
- public static final int EMUsFromColumnWidth(int columnWidth) {
- return (int) (columnWidth /256d * EMUUtils.EMU_PER_CHARACTER);
- }
-
- /**
- * @param twips (1/20th of a point) typically a row height
- * @return EMUs
- */
- public static final int EMUsFromTwips(short twips) {
- return (int) (twips / 20d * EMU_PER_POINT);
- }
-
- /**
- * @param points (fractional)
- * @return EMUs
- */
- public static final int EMUsFromPoints(float points) {
- return (int) (points * EMU_PER_POINT);
- }
-}