From user-return-23106-archive-asf-public=cust-asf.ponee.io@poi.apache.org Thu Aug 16 18:38:01 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 46F3B180675 for ; Thu, 16 Aug 2018 18:38:00 +0200 (CEST) Received: (qmail 58901 invoked by uid 500); 16 Aug 2018 16:37:59 -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 58889 invoked by uid 99); 16 Aug 2018 16:37:58 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2018 16:37:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id F3DE4C1A71 for ; Thu, 16 Aug 2018 16:37:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.801 X-Spam-Level: * X-Spam-Status: No, score=1.801 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, MIME_QP_LONG_LINE=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id XlegWUAK5afn for ; Thu, 16 Aug 2018 16:37:56 +0000 (UTC) Received: from atl4mhob11.registeredsite.com (atl4mhob11.registeredsite.com [209.17.115.49]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 574265F3BE for ; Thu, 16 Aug 2018 16:37:55 +0000 (UTC) Received: from mailpod.hostingplatform.com (atl4qobmail03pod1.registeredsite.com [10.30.71.115]) by atl4mhob11.registeredsite.com (8.14.4/8.14.4) with ESMTP id w7GGbpPb028661 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 16 Aug 2018 12:37:52 -0400 Received: (qmail 13853 invoked by uid 0); 16 Aug 2018 16:37:51 -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; 16 Aug 2018 16:37:51 -0000 User-Agent: Microsoft-MacOutlook/10.10.0.180812 Date: Thu, 16 Aug 2018 11:37:50 -0500 Subject: Re: General Support for Percentage Values? From: Eliot Kimber To: POI Users List Message-ID: <8276B321-D503-4658-AAFA-46A94BE96026@contrext.com> Thread-Topic: General Support for Percentage Values? References: <04CFCFF1-98B4-4C77-AB6F-856A66427D10@contrext.com> <4CBBBDD7FB566C4DB70EB7A04E0B466F1E071568@exchange3> <76FB882F-D346-4224-9A30-5CAE5C0D5E50@contrext.com> <4CBBBDD7FB566C4DB70EB7A04E0B466F1E07159A@exchange3> In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable Shouldn't we be reflecting the latest schemas? Cheers, E. -- Eliot Kimber http://contrext.com =20 =EF=BB=BFOn 8/16/18, 11:25 AM, "Mark Murphy" wrote: Use 1st edition, part 4. The CT classes were all generated from the 1st edition schema. =20 On Thu, Aug 16, 2018 at 12:17 PM Eliot Kimber wr= ote: =20 > I'm using ECMA-376 3rd Edition / June 2011, Office Open XML File Form= ats =E2=80=93 > Part 1 > > Although it looks like there's a 5th edition from 2015. I'll get that= one: > > https://www.ecma-international.org/publications/standards/Ecma-376.ht= m > > Cheers, > > E. > -- > Eliot Kimber > http://contrext.com > > > =EF=BB=BFOn 8/16/18, 10:55 AM, "Murphy, Mark" w= rote: > > Which version of the spec are you reading? We are using Version 1= . > Though we sometimes deal with later version artifacts, the CT and ST > classes are all version 1. > > -----Original Message----- > From: Eliot Kimber [mailto:ekimber@contrext.com] > Sent: Thursday, August 16, 2018 11:00 AM > To: POI Users List > Subject: Re: General Support for Percentage Values? > > I'm reading section 17.4.88 Table Measurement (CT_TblWidth), whic= h > shows this example: > > <=E2=80=A6 w:type=3D"pct" w:w=3D"100%"/> > > And which refers to 17.18.107 ST_MeasurementOrPercent (Measuremen= t or > Percentage Value) as the definition of the @w:w attribute. > > It says it's a union of two types: ST_DecimalNumberOrPercent and > ST_UniversalMeasure. ST_DecimalNumberOrPercent then says it's a unio= n of > ST_Percentage, 22.9.2.9 ST_Percentage (Percentage Value with Sign), w= hich > has this example: > > > > I tried some experiements and if I modify the XML for my table to= e.g.: > > > > And open it, Word correctly reflects the 50% width BUT when I sav= e > from Word the @w:w value is set to 2500 (50 * 50). > > So clearly Word prefers to store things as integers, which makes > sense, but it will read the % string value as defined in the spec. > > I'm curious--what part of the spec are you reading that indicates= that > value is always an integer? I'm not doubting that it says that, but I > didn't get to that part of the spec starting from the definitions for= table > width. > > But this does suggest that my code that lets you set and get the = table > width (and the table cell widths, as you indicate, which I also need)= is > appropriate, in that it conforms to the spec, works with Word, and pr= ovides > the convenience of allowing direct specific of the literal decimal > percentage strings to .setWidth(). > > At the same time, there's no reason not to have the POI code do t= he > percentage-to-integer conversion when it sets the @w:w value. > > Cheers, > > Eliot > > -- > Eliot Kimber > http://contrext.com > > > =EF=BB=BFOn 8/16/18, 8:42 AM, "Murphy, Mark" > wrote: > > According to the spec, w:val is always an integer value. What= that > integer represents depends on the w:type value. If w:type=3D"auto" then= it > appears that w:val=3D0, or may even be ignored, but that will depend on= the > table width algorithm. I didn't look at that just now, it is very com= plex. > > If w:type=3D"dxa" then w:val is an integer that represents 20th= s of > a point. In that case I would take the value you specify in setCellWi= dth > and multiply by 20 to get the integer for val (don't make the user pr= ovide > val in 20ths of a point). > > If w:type=3D"pct" then w:val is an integer that represents 50th= s of > a point. In that case I would take the value specified in setCellWidt= h and > multiply by 50 to get the integer for w:val (again don't make the use= r > provide val in 50ths of a percent). > > getCellWidth will have to honor these conventions as well. To > retrieve cell width in points, you will have to divide w:val by 20, a= nd to > retrieve cell widths in percents, you will have to divide by 50. Note= , > there is no real way to convert between points and percent. > > -----Original Message----- > From: Eliot Kimber [mailto:ekimber@contrext.com] > Sent: Wednesday, August 15, 2018 7:02 PM > To: POI Users List > Subject: Re: General Support for Percentage Values? > > If I manually set the @w:w value to the percentage string the= n I > can get back the percentage and convert it to a double when the width= type > is set to percentage. > > But I think there really needs to be a method on CTTblWidth t= hat > can return an STPercentage, parallel to xgetWidth(), which returns a > BigDecimal. > > Cheers, > > E. > > -- > Eliot Kimber > http://contrext.com > > > =EF=BB=BFOn 8/15/18, 5:39 PM, "Eliot Kimber" = wrote: > > (This is in the context of setting the width on XWPFTable= .) > > 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 separate class that would just end up creating a percentag= e > string anyway. This also matches the way the API is likely to be used= , > e.g., getting percentage value strings from some incoming source. > > So I added a new setWidth(String widthValue) method to > XWPFTable() which validates that it's a good value ("auto", an intege= r, or > a percentage) and then if it's good, sets the value appropriately. > > I also created a new method, getWidthDecimal(), to return= the > width value as a decimal (because percentages can be decimal values). > > Using this test case: > > XWPFDocument doc =3D new XWPFDocument(); > > XWPFTable xtab =3D doc.createTable(); > > assertEquals(0, xtab.getWidth()); > assertEquals(STTblWidth.AUTO, xtab.getWidthType()= ); > > xtab.setWidth(1000); > assertEquals(STTblWidth.DXA, xtab.getWidthType())= ; > assertEquals(1000, xtab.getWidth()); > > xtab.setWidth("auto"); > assertEquals(STTblWidth.AUTO, xtab.getWidthType()= ); > assertEquals(0, xtab.getWidth()); > assertEquals(0.0, xtab.getWidthDecimal(), 0.01); > > xtab.setWidth("999"); > assertEquals(STTblWidth.DXA, xtab.getWidthType())= ; > > assertEquals(999, xtab.getWidth()); > > xtab.setWidth("50.5%"); > assertEquals(STTblWidth.PCT, xtab.getWidthType())= ; > > assertEquals(50.5, xtab.getWidthDecimal(), 0.01); > assertEquals(50.5, > xtab.getCTTbl().getTblPr().getTblW().xgetW().getBigDecimalValue().dou= bleValue(), > 0.01); > > Everything passes until the last test, where the value > returned by getWidthDecimal() is 50.0, not 50.5. > > It looks like the underlying CT class methods always set = the > value as an integer, even when using CTTblWidth.setBigDecimalValue(): > > } else if (widthValue.matches("[0-9]+(\\.[0-9]+)?= %")) { > String numericPart =3D widthValue.substring(0, > widthValue.length() - 1); > STDecimalNumber number =3D > STDecimalNumber.Factory.newInstance(); > number.setBigDecimalValue(new > BigDecimal(numericPart)); > ctWidth.xsetW(number); > ctWidth.setType(STTblWidth.PCT); > > Debugging through this code I see that the @w:val attribu= te is > "50" rather than "50.5" after the xsetW() method call. > > This appears to be happening at a very low level. > > Is there a way to fix this so that percentages can be dec= imals > or have I misunderstood the specs and percentages should actually alw= ays be > integers (although I'm pretty sure the spec allows fractional percent= ages). > > Thanks, > > Eliot > -- > Eliot Kimber > http://contrext.com > > > =EF=BB=BFOn 8/15/18, 3:40 PM, "Eliot Kimber" > wrote: > > I need to extend the options for setting table widths= . > > Per the spec, a table's width can be an absolute > measurement, a percentage value, or the keyword "auto". > > Right now XWPFTable.setWidth() only takes an integer. > > I'd like to extend it to take in addition a percentag= e > value or the value "auto" (which I suppose conceptually is an enumera= tion > with one possible value). > > 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. > > Am I missing something for working with percentage va= lues > in the XWPF API? > > Thanks, > > E.=EF=BB=BF > > -- > Eliot Kimber > http://contrext.com > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.o= rg > For additional commands, e-mail: user-help@poi.apache= .org > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For > additional commands, e-mail: user-help@poi.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > > > > -----------------------------------------------------------------= ---- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For > additional commands, e-mail: user-help@poi.apache.org > > > -----------------------------------------------------------------= ---- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org > For additional commands, e-mail: user-help@poi.apache.org > > =20 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org