Page 1 of 1

Tab size

PostPosted: Thu May 09, 2013 2:11 am
by Joerakel
Hi,

I have two questions. Since tabs are converted to 3 times &nbsp; (while converting to xhtml) I am trying to program the right conversion myself but for this I need to know if Word has a standard size for the <tab /> elements (like 30px or something).
-> Question one: is there a standard size for <tab /> ?

I figured out that when I want to position for example text then I need to divide the numbers which Word uses in it's xml's by about 572 to get correct distance in cm (like <w:tab w:pos="2410" w:val="left"/> -> 2410/572 = 4.21cm -> <span style="font-size: 7.0pt; position:absolute; left:4.21cm;">some text</span>) .
-> Question two: does Word generate these sizes (w:pos="2410") somehow related to my screen size or can I generally use my calculation ( /572) and the result will look the same on every screen?
(I mean if I create one Docx on my screen and another one on a bigger screen and then convert both with my calculation implemented OR does any other factor change the size of w:pos so I can't do it like that)

Info
- if I use 2410 as px it's way to large
- first question refers to sections where there is no tab size section in front like "<w:tab w:pos="24.....", just <tab />

hopefully this was not written in a tooo confusing style... I don't write in english to much

cheers Joe

Re: Tab size

PostPosted: Thu May 09, 2013 8:19 am
by jason
Hi Joe

Joerakel wrote:-> Question one: is there a standard size for <tab /> ?


This code (from src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/Conversion.java) may help explain:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    private static int getDistanceToNextTabStop(int pos, int numWidth, Tabs pprTabs, DocumentSettingsPart settings) {
               
                int pdbs = 0;
                int defaultTab = 360;
                if (pprTabs!=null
                                && pprTabs.getTab()!=null
                                && pprTabs.getTab().size()>0) {
                       
                        for ( CTTabStop tabStop : pprTabs.getTab() ) {
                                        if (tabStop.getPos().intValue()> (pos+ numWidth) ) {
                                                log.debug("tab stop: using specified");
                                                return (tabStop.getPos().intValue() - pos);
                                        }
                        }
                       
                }
               
                // The default tabs continue to apply after the specified ones
                if (settings!=null
                                && settings.getJaxbElement().getDefaultTabStop()!=null ) {
                        CTTwipsMeasure twips = settings.getJaxbElement().getDefaultTabStop();
                        defaultTab = twips.getVal().intValue();
                       
                        if (defaultTab>0) {
                                log.debug("tab stop: using default from docx");
                                int tabNUmber = (int)Math.floor((pos+numWidth)/defaultTab);
                                int nextTabPos = defaultTab*(tabNUmber+1);
                                return nextTabPos - pos;
                        }
                }

                log.debug("tab stop: assuming default tab 360");
                int tabNUmber = (int)Math.floor((pos+numWidth)/defaultTab);
                int nextTabPos = defaultTab*(tabNUmber+1);
                return nextTabPos - pos;
    }
 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4


Joerakel wrote:Question two: does Word generate these sizes (w:pos="2410")


No, those units are twips, twentieths of a point. See also https://github.com/plutext/docx4j/blob/ ... ement.java

hope this helps .. Jason