From user-return-23096-archive-asf-public=cust-asf.ponee.io@poi.apache.org Thu Aug 16 01:01:49 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7F901180626 for ; Thu, 16 Aug 2018 01:01:48 +0200 (CEST) Received: (qmail 67057 invoked by uid 500); 15 Aug 2018 23:01:47 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 67046 invoked by uid 99); 15 Aug 2018 23:01:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2018 23:01:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 573D8C7330 for ; Wed, 15 Aug 2018 23:01:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.8 X-Spam-Level: * X-Spam-Status: No, score=1.8 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id PeiAD1ZMgOiu for ; Wed, 15 Aug 2018 23:01:41 +0000 (UTC) Received: from atl4mhob05.registeredsite.com (atl4mhob05.registeredsite.com [209.17.115.43]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 6BC935F1A1 for ; Wed, 15 Aug 2018 23:01:41 +0000 (UTC) Received: from mailpod.hostingplatform.com (atl4qobmail02pod1.registeredsite.com [10.30.71.114]) by atl4mhob05.registeredsite.com (8.14.4/8.14.4) with ESMTP id w7FN1dWT022897 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 15 Aug 2018 19:01:39 -0400 Received: (qmail 956 invoked by uid 0); 15 Aug 2018 23:01:39 -0000 X-TCPREMOTEIP: 136.62.89.1 X-Authenticated-UID: ekimber@contrext.com Received: from unknown (HELO ?192.168.1.200?) (ekimber@contrext.com@136.62.89.1) by 0 with ESMTPA; 15 Aug 2018 23:01:38 -0000 User-Agent: Microsoft-MacOutlook/10.10.0.180812 Date: Wed, 15 Aug 2018 18:01:38 -0500 Subject: Re: General Support for Percentage Values? From: Eliot Kimber To: POI Users List Message-ID: Thread-Topic: General Support for Percentage Values? References: <04CFCFF1-98B4-4C77-AB6F-856A66427D10@contrext.com> In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable If I manually set the @w:w value to the percentage string then I can get ba= ck the percentage and convert it to a double when the width type is set to p= ercentage. But I think there really needs to be a method on CTTblWidth that can return= an STPercentage, parallel to xgetWidth(), which returns a BigDecimal. Cheers, E. -- Eliot Kimber http://contrext.com =20 =EF=BB=BFOn 8/15/18, 5:39 PM, "Eliot Kimber" wrote: (This is in the context of setting the width on XWPFTable.) =20 I decided that the best (and simplest) approach would be to use strings= to set the width value for "auto" and percentages, rather than creating a s= eparate class that would just end up creating a percentage string anyway. Th= is also matches the way the API is likely to be used, e.g., getting percenta= ge value strings from some incoming source. =20 So I added a new setWidth(String widthValue) method to XWPFTable() whic= h validates that it's a good value ("auto", an integer, or a percentage) and= then if it's good, sets the value appropriately. =20 I also created a new method, getWidthDecimal(), to return the width val= ue as a decimal (because percentages can be decimal values). =20 Using this test case: =20 XWPFDocument doc =3D new XWPFDocument(); =20 XWPFTable xtab =3D doc.createTable(); =20 assertEquals(0, xtab.getWidth()); assertEquals(STTblWidth.AUTO, xtab.getWidthType()); =20 xtab.setWidth(1000); assertEquals(STTblWidth.DXA, xtab.getWidthType()); assertEquals(1000, xtab.getWidth()); =20 xtab.setWidth("auto"); assertEquals(STTblWidth.AUTO, xtab.getWidthType()); assertEquals(0, xtab.getWidth()); assertEquals(0.0, xtab.getWidthDecimal(), 0.01); =20 xtab.setWidth("999"); assertEquals(STTblWidth.DXA, xtab.getWidthType()); = =20 assertEquals(999, xtab.getWidth()); =20 xtab.setWidth("50.5%"); assertEquals(STTblWidth.PCT, xtab.getWidthType()); =20 assertEquals(50.5, xtab.getWidthDecimal(), 0.01); assertEquals(50.5, xtab.getCTTbl().getTblPr().getTblW().xgetW()= .getBigDecimalValue().doubleValue(), 0.01); =20 Everything passes until the last test, where the value returned by getW= idthDecimal() is 50.0, not 50.5. =20 It looks like the underlying CT class methods always set the value as a= n integer, even when using CTTblWidth.setBigDecimalValue(): =20 } else if (widthValue.matches("[0-9]+(\\.[0-9]+)?%")) { String numericPart =3D widthValue.substring(0, widthValue.len= gth() - 1); STDecimalNumber number =3D STDecimalNumber.Factory.newInstanc= e(); number.setBigDecimalValue(new BigDecimal(numericPart)); ctWidth.xsetW(number); ctWidth.setType(STTblWidth.PCT); =20 Debugging through this code I see that the @w:val attribute is "50" rat= her than "50.5" after the xsetW() method call. =20 This appears to be happening at a very low level. =20 Is there a way to fix this so that percentages can be decimals or have = I misunderstood the specs and percentages should actually always be integers= (although I'm pretty sure the spec allows fractional percentages). =20 Thanks, =20 Eliot -- Eliot Kimber http://contrext.com =20 =20 =EF=BB=BFOn 8/15/18, 3:40 PM, "Eliot Kimber" wrote: =20 I need to extend the options for setting table widths. =20 Per the spec, a table's width can be an absolute measurement, a per= centage value, or the keyword "auto". =20 Right now XWPFTable.setWidth() only takes an integer. =20 I'd like to extend it to take in addition a percentage value or the= value "auto" (which I suppose conceptually is an enumeration with one possi= ble value). =20 There doesn't seem to be a class that represents a percentage value= (at least I couldn't find any declarations with the string "perc" in them. =20 Am I missing something for working with percentage values in the XW= PF API? =20 Thanks, =20 E.=EF=BB=BF =20 -- Eliot Kimber http://contrext.com =20 =20 =20 =20 -------------------------------------------------------------------= -- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org =20 =20 =20 =20 =20 =20 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org =20 =20 =20 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org