Page 1 of 1

Numbered lists are rendered with bugs?

PostPosted: Wed Jan 22, 2014 12:14 am
by Anton Reshetnikov
Hello,

I'm trying to implement my conversion of DOCX to HTML and plain text. I use the org.docx4j.model.listnumbering.Emulator's getNumber() method to render numbered lists. When I use decimal numbering format everything is fine. But when using letters here is what I get:

Code: Select all
a. One
b. Two
c. Three
d. Four
e. Five
f. Six
g. Seven
h. Eight
i. Nine
a9. Ten
aa. Eleven
ab. Twelve
ac. Thirteen


I've looked into the debug log and found that it internally uses this class: https://github.com/plutext/docx4j/blob/ ... etter.java

Here's the method:

Code: Select all
public String format( int in ) {
               
                String str = Integer.toString(in);
                StringBuilder out = new StringBuilder();
               
                for (int i = 0; i < str.length(); i++) {
                        int dig = Character.digit(str.charAt(i), 36);
                        char cdig = Character.forDigit(dig + 9, 36);
                        log.debug(str.charAt(i) + " --> " + cdig);
                        out.append(cdig);
                }               
                return out.toString();               
        }


It looks like it generates a letter for every digit of the number instead of generating for the whole number. So in alphabetic order 9th letter is "i" and 10th is "j", but instead of "j" we get "a9". "a" for the 1 and (for some reason) "9" for the 0.

Anyway, is it me doing something wrong, or is it really a bug? I'm attaching the example of input, output, the log and my code (not full, but I can send the full working app if you need).

Re: Numbered lists are rendered with bugs?

PostPosted: Wed Jan 22, 2014 8:56 pm
by jason
Yes, looks like a bug.

If you fix it, happy to accept a contrib (under ASL v2 license).

Otherwise, please file an issue at https://github.com/plutext/docx4j/issues/new

Re: Numbered lists are rendered with bugs?

PostPosted: Fri Jan 24, 2014 5:13 am
by Anton Reshetnikov
Thanks for response. I'll try to contribute. Is it better to send you a diff or to create a pull request on github?

Re: Numbered lists are rendered with bugs?

PostPosted: Fri Jan 24, 2014 6:13 am
by jason
Pull request on GitHub please.

Re: Numbered lists are rendered with bugs?

PostPosted: Sun Jan 26, 2014 3:19 pm
by Anton Reshetnikov

Re: Numbered lists are rendered with bugs?

PostPosted: Thu Jan 30, 2014 10:09 am
by jason
Merged, thank you. This will make it into 3.0.1, to be released soon.

Re: Numbered lists are rendered with bugs?

PostPosted: Wed Jun 19, 2019 1:49 am
by masadek
Hi Jason and Anton,

I'm using version 3.3.1 and it had a bug that it can't print characters after z, like the following example.
Code: Select all
...
z)   26
aa)   27
bb)   28
...
aaa) 53
bbb) 54


I found out that you added a fix in version 3.3.7, which currently prints as: (aa, ab, ac, ...) and so on, which is different from word default order shown above

I think the fix should be as shown below:
Code: Select all
   public String format( int in ) {
      StringBuilder out = new StringBuilder();
      int num = (in % 26 > 0) ? (in % 26) : 26; // for z
      int count = (int) java.lang.Math.ceil((double) in / 26);
      while(count > 0) {   
         out.append(Character.forDigit(num+9, 36));
         count--;
      }
      return out.toString();      
   }


I'll try to fix it and send you a pull request

Re: Numbered lists are rendered with bugs?

PostPosted: Sat Jun 22, 2019 4:32 am
by jason
Hi Masadek

I've confirmed in Word 2010 and 2016 (on Windows) that the numbering is as you describe (!).

So yes, if you can send a pull request (and ideally a unit test), that'd be great. Pull request needs to be against master branch please (which is docx4j 8.x).

thanks .. Jason