POI » TestHSSFClientAnchor.java源码

package org.apache.poi.hssf.usermodel;
019 
020 import junit.framework.TestCase;
021 import org.apache.poi.ddf.EscherClientAnchorRecord;
022 import org.apache.poi.hssf.model.ConvertAnchor;
023 
024/***
025  * Various tests for HSSFClientAnchor.
026  *
027  * @author Glen Stampoultzis (glens at apache.org)
028  * @author Yegor Kozlov (yegor at apache.org)
029  */
030 public final class TestHSSFClientAnchor extends TestCase {
031     public void testGetAnchorHeightInPoints() {
032         HSSFWorkbook wb = new HSSFWorkbook();
033         HSSFSheet sheet = wb.createSheet("test");
034         HSSFClientAnchor a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0);
035         float p = a.getAnchorHeightInPoints(sheet);
036         assertEquals(12.7,p,0.001);
037 
038         sheet.createRow(0).setHeightInPoints(14);
039         a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0);
040         p = a.getAnchorHeightInPoints(sheet);
041         assertEquals(13.945,p,0.001);
042 
043         a = new HSSFClientAnchor(0,0,1023,127,(short)0,0,(short)0,0);
044         p = a.getAnchorHeightInPoints(sheet);
045         assertEquals(6.945,p,0.001);
046 
047         a = new HSSFClientAnchor(0,126,1023,127,(short)0,0,(short)0,0);
048         p = a.getAnchorHeightInPoints(sheet);
049         assertEquals(0.054,p,0.001);
050 
051         a = new HSSFClientAnchor(0,0,1023,0,(short)0,0,(short)0,1);
052         p = a.getAnchorHeightInPoints(sheet);
053         assertEquals(14.0,p,0.001);
054 
055         sheet.createRow(0).setHeightInPoints(12);
056         a = new HSSFClientAnchor(0,127,1023,127,(short)0,0,(short)0,1);
057         p = a.getAnchorHeightInPoints(sheet);
058         assertEquals(12.372,p,0.001);
059 
060     }
061 
062     /***
063      * When HSSFClientAnchor is converted into EscherClientAnchorRecord
064      * check that dx1, dx2, dy1 and dy2 are written "as is".
065      * (Bug 42999 reported that dx1 and dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.)
066      */
067     public void testConvertAnchor() {
068         HSSFClientAnchor[] anchor = {
069             new HSSFClientAnchor( 0 0 0 0 ,(short)01,(short)1,3),
070             new HSSFClientAnchor( 100 0 900 255 ,(short)01,(short)1,3),
071             new HSSFClientAnchor( 900 0 100 255 ,(short)01,(short)1,3)
072         };
073         for (int i = 0; i < anchor.length; i++) {
074             EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor[i]);
075             assertEquals(anchor[i].getDx1(), record.getDx1());
076             assertEquals(anchor[i].getDx2(), record.getDx2());
077             assertEquals(anchor[i].getDy1(), record.getDy1());
078             assertEquals(anchor[i].getDy2(), record.getDy2());
079             assertEquals(anchor[i].getCol1(), record.getCol1());
080             assertEquals(anchor[i].getCol2(), record.getCol2());
081             assertEquals(anchor[i].getRow1(), record.getRow1());
082             assertEquals(anchor[i].getRow2(), record.getRow2());
083         }
084     }
085 
086     public void testAnchorHeightInPoints(){
087         HSSFWorkbook wb = new HSSFWorkbook();
088         HSSFSheet sheet = wb.createSheet();
089 
090         HSSFClientAnchor[] anchor = {
091             new HSSFClientAnchor( 0 0,    0 0 ,(short)01,(short)13),
092             new HSSFClientAnchor( 0 254 0 126 ,(short)01,(short)13),
093             new HSSFClientAnchor( 0 128 0 128 ,(short)01,(short)13),
094             new HSSFClientAnchor( 0 0 0 128 ,(short)01,(short)13),
095         };
096         float[] ref = {25.5f, 19.125f, 25.5f, 31.875f};
097         for (int i = 0; i < anchor.length; i++) {
098             float height = anchor[i].getAnchorHeightInPoints(sheet);
099             assertEquals(ref[i], height, 0);
100         }
101     }
102}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值