There should be issues for the mentioned problems, where further details on the problems and their patches can be added to:
https://issues.apache.org/jira/browse/ODFTOOLKIT-469 - Setting Local results to invalid ODF documents https://issues.apache.org/jira/browse/ODFTOOLKIT-470 - Font size change does not work in Microsoft Office 2016 Hope you are at the beginning of a great week! Svante ᐧ 2018-01-14 11:49 GMT+01:00 Svante Schubert <svante.schub...@gmail.com>: > Hello Joseph, > > The problem is an incompatibility of Microsoft Office, which needs a > different handling and in addition a missing feature/bug in the Simple API. > > Let me tell you what I did: > As you are working with the Simple API, I added a regression test of your > scenario to this project. > > 1. Therefore I cloned myself a fresh copy of the project, see > http://incubator.apache.org/odftoolkit/source.html > <http://incubator.apache.org/odftoolkit/source.html> > 2. Copied your test files into the (typical Maven) test file folder of > the project: simple\src\test\resources (I actually only need your > given text file) > 3. Copied your source code at the end of a test class of Simple API, > i.e. I have used org.odftoolkit.simple.text.FooterTest.java within the > Simple API > - Exchanged you main function with a JUnit test function > - Exchanged the input and output files names coming from the main > function as arguments with fixed names > - Exchanged the access to the files from simple string to access > the test files folder path (it was aside the command line call and is > now > at runtime "simple\target\test-classes") with > IN => ResourceUtilities.getAbsolutePath(TEXT_DATA_INPUT_FILE_NAME) > OUT => doc.save(ResourceUtilities.newTestOutputFile(ODT_DATA_ > OUTPUT_FILE_NAME)); > > I have validated your given output file and the new output file of the > test and both only showed me the problems having text property of language > and locale within a table and table-row default styles. The header/footer > is now correct. > I have saved the ODT document right after creation before applying your > test changes and the local problem does not exist, so the issue is within > the test. > > Unfortunately, when manually fixing it, Word still does not show the > correct font size. I have tried several things to work on the Microsoft > Office bug: > > 1. Removed sections > 2. Moved the text properties from the paragraphs to an own text style > using spans > 3. .. > > Then I spotted accidentally the problem. It is possible to set different > font attributes for three types of fonts: Western, CJK (Chinese Japanese > and Korean) and complex (e.g. Arabian): > style:font-size-asian="12pt" style:font-size-complex="12pt" were still > using a different size, which results into an error in MS Office, but works > fine with Microsoft. > see http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1. > html#property-style_font-size-complex > > Fixing those manually solved the problem. > I was deliberating if changing one font property, shall change the > property of all three language groups, but it would remove ODF > functionality. > Instead, to be able to be compatible with Microsoft Office, I have > extended the test to add the same new font size for a South Korean and > Saudi Arabian Java Locale. > > Well, what shall I say? It does not work :/ But now it comes down to debug > Simple API code, which is as alien source code to me as to you. > As mentioned before I am focused on the ODFDOM project with its source > code generation within the ODF Toolkit. > So you - or anyone interested in helping you - should take over from here, > as I have to continue on projects, bringing income for my family :/ > To make it easy for anyone to continue, I have simply pushed the test to > the SVN trunk. So simply pull a fresh copy from the project (see URL above) > and you may find the test method at the end of org.odftoolkit.simple.text. > FooterTest > > As proof I have attached a document working in MS Office resulting from > the test document, with only manually (via JEdit) fixed font size > properties, e.g. style:font-size-asian="8.0pt" style:font-size-complex="8.0pt" > (quite at the end, the last page of the text file) > > Good luck, Joseph! > Svante > > > > > > > > ᐧ > > 2018-01-14 3:28 GMT+01:00 Joseph D. Wagner <j...@josephdwagner.info>: > >> The first document, attached, is created with the SimpleAPI. I >> rearranged the header and footer code to put them in the "proper" order as >> you previously suggested. However, it had no impact. >> >> If you look at the .odt file in Word, you'll notice the only line that >> has the Font Size correctly set is the first line of the main body. All >> other fonts are set to size 12. I think this has something to do with the >> addParagraph function and setFont on the Paragraph class. Below is my code >> for my entire program (relatively short). >> >> Here are some couter-examples of it working: >> >> 1) You'll notice the first line uses appendTextContent, and that one set >> the Font Size correctly. However, all subsequent calls using addParagraph >> do not set the Font Size correctly, at least not in Word. >> >> 2) If I put the footer inside of a table, like on your website's >> examples, it will set the Font Size correctly then. (However, I couldn't >> figure out how to put the PageNumber and PageCount variables inside a cell.) >> >> 3) If I set the font size LARGER than 12, like 16, it will set the Font >> Size correctly. >> >> I think this is the root of the problem. If we figure out why Word isn't >> recognizing the Font Size when setFont is called on a Paragraph and fix it, >> I think that will fix it in the header, footer, and main body. >> >> One more note: I would have thought that TextDocument.save() would >> correctly handle the ordering of elements within a document, like header >> before footer. If it doesn't, I would like to suggest making that happen >> as a future feature. The SimpleAPI is much less useful if developers not >> familiar with the ODF specs have to know proper ordering. HOWEVER, >> something makes me think this isn't the real problem. >> >> Thanks again for your help. >> >> public static void main(String[] args) throws Exception { >> // Verifies two files were passed to the command line arguments >> if(args.length != 2) { >> System.err.println("usage: plaintext2odt infile outfile"); >> System.exit(1); >> } >> >> // Opens infile >> BufferedReader infile = new BufferedReader(new >> FileReader(args[0])); >> >> // Creates new doc and sets defaults >> Locale locale = new Locale("en", "US"); >> Font font = new Font("Courier New", >> StyleTypeDefinitions.FontStyle.REGULAR, >> 10, locale); >> TextDocument doc = TextDocument.newTextDocument(); >> MasterPage master = MasterPage.getOrCreateMasterPage(doc, >> "Standard"); >> master.setPageHeight(279.4); >> master.setPageWidth(215.9); >> master.setMargins(19.05, 19.05, 19.05, 19.05); // 19.05 mm = 0.75 >> in >> doc.setPageColumns(2, 0.635); // 0.635 cm = 0.25 in >> doc.setLocale(locale); >> >> // Adds header >> Header header = doc.getHeader(); >> Section headersection = header.appendSection("Title"); >> Paragraph headerparagraph = headersection.addParagraph(null); >> headerparagraph.setFont(font); >> headerparagraph.appendTextContent(infile.readLine()); >> headerparagraph.setHorizontalAlignment(StyleTypeDefinitions. >> HorizontalAlignmentType.CENTER); >> >> // Adds Page X of Y to the footer >> Font fontsmaller = new Font("Courier New", >> StyleTypeDefinitions.FontStyle.ITALIC, 8, Color.RED, locale); >> Footer footer = doc.getFooter(); >> Section footersection = footer.appendSection("Page Numbers"); >> Paragraph footerparagraph = footersection.addParagraph("Pa >> ge\u00A0"); >> Fields.createCurrentPageNumberField(footerparagraph. >> getOdfElement()); >> footerparagraph.appendTextContent("\u00A0of\u00A0"); >> Fields.createPageCountField(footerparagraph.getOdfElement()); >> footerparagraph.setFont(fontsmaller); // Doesn't work here >> footerparagraph.setHorizontalAlignment(StyleTypeDefinitions. >> HorizontalAlignmentType.CENTER); >> >> // Special handling for first line >> Paragraph p = doc.getParagraphByIndex(0, false); >> p.setFont(font); >> infile.readLine(); >> p.appendTextContent(infile.readLine()); >> >> // Loops over all other lines >> String inline = new String(); >> while ((inline = infile.readLine()) != null) { >> // p.appendTextContent("\r\n" + inline.replaceAll("\n", >> "\r\n")); // Works, because it doesn't use addParagraph >> p = doc.addParagraph(inline.replaceAll("\n", "\r\n")); >> p.setFont(font); // Does not work, because it uses >> addParagraph >> } >> infile.close(); >> >> // Saves outfile >> FileOutputStream outfile = new FileOutputStream(args[1]); >> doc.save(outfile); >> } >> >> On 01/13/2018 09:29 AM, Svante Schubert wrote: >> >> Both documents created with SimpleAPI? I might be able to take a look at >> it tomorrow. Are you able to add a test creating the erraneous document? >> Just copy from the existing tests. >> >> Cheers >> Svante >> >> Am 13.01.2018 13:26 schrieb "Joseph D. Wagner" <j...@josephdwagner.info>: >> >>> Thanks. The document was created with the Simple API. So what are the >>> implications? Bug in Simple API, ODFDOM, or the java I wrote that called >>> the Simple API? >>> >>> Joseph D. Wagner >>> -- >>> Sent from my Android device. >>> >>> ------------------------------ >>> *From:* Svante Schubert <svante.schub...@gmail.com> >>> *Sent:* January 13, 2018 2:37:21 AM PST >>> *To:* "Joseph D. Wagner" <j...@josephdwagner.info> >>> *Cc:* odf-dev@incubator.apache.org >>> *Subject:* Re: Trouble with Footer Font Size - Adding Page X of Y to >>> Footer >>> >>> Hello Joseph, >>> >>> first step is usually to check for validation problems. >>> There is a free online validator from The Document Foundation, which is >>> using our Apache ODF Toolkit project (incubating) Validator with their own >>> logo (which is fine, as they are paying the server bill). >>> >>> You 'broken' document - you had called "works in libreoffice - not in >>> word.odt" document is also invalid at various points, (the working one has >>> 'only' the common version attribute problem, which is a known and long >>> story). >>> >>> The broken document shows the following errors >>> works in libreoffice - not in word.odt/styles.xml[2,3901]: Error: element >>> "style:text-properties" was found where no element may occur >>> ties fo:country="US" >>> fo:language="en"/></style:default-style><style:default-sty >>> ----^ >>> works in libreoffice - not in word.odt/styles.xml[2,4079]: Error: element >>> "style:text-properties" was found where no element may occur >>> ties fo:country="US" fo:language="en"/></style:default-style><style:style >>> style ----^ >>> works in libreoffice - not in word.odt/styles.xml[2,90333]: Error: tag >>> name "style:header" is not allowed. Possible tag names are: >>> <a>,<animate>,<animateColor>,<animateMotion>,<animateTransfo >>> rm>,<audio>,<caption>,<circle>,<command>,<connector>,<contro >>> l>,<custom-shape>,<ellipse>,<footer-left>,<forms>,<frame>,< >>> g>,<iterate>,<layer-set>,<line>,<measure>,<notes>,<page- >>> thumbnail>,<par>,<path>,<polygon>,<polyline>,<rect>,<re >>> gular-polygon>,<scene>,<seq>,<set>,<transitionFilter> >>> t:section></style:footer><style:header><text:section >>> text:display="true" text:n ----^ works in libreoffice - not in >>> word.odt/styles.xml: Info: 3 errors, no warnings >>> >>> >>> As this is not very helpful as everything is in a single 2nd line, I >>> have loaded the document into JEdit opening the styles.xml using the JEdit >>> archive extension and doing an indent using the Jedit XML extension and >>> saving the new file into the ZIP with Jedit back again. >>> >>> Now it is easier to find within a text editor: >>> works in libreoffice - not in word.odt/styles.xml[25,61]: Error: element >>> "style:text-properties" was found where no element may occur >>> <style:text-properties fo:country="US" fo:language="en"/> ----^ works >>> in libreoffice - not in word.odt/styles.xml[29,61]: Error: element >>> "style:text-properties" was found where no element may occur >>> <style:text-properties fo:country="US" fo:language="en"/> ----^ works >>> in libreoffice - not in word.odt/styles.xml[1082,18]: Error: tag name >>> "style:header" is not allowed. Possible tag names are: >>> <a>,<animate>,<animateColor>,<animateMotion>,<animateTransfo >>> rm>,<audio>,<caption>,<circle>,<command>,<connector>,<contro >>> l>,<custom-shape>,<ellipse>,<footer-left>,<forms>,<frame>,< >>> g>,<iterate>,<layer-set>,<line>,<measure>,<notes>,<page- >>> thumbnail>,<par>,<path>,<polygon>,<polyline>,<rect>,<re >>> gular-polygon>,<scene>,<seq>,<set>,<transitionFilter> >>> >>> The first two problem is only about text properties within a table and >>> paragraph style, where they are not allowed. What application created this >>> document? We should file an issue. :) >>> To check if kind of problem, you may look into the specification >>> <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html> >>> or the ODF XML grammar >>> <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-schema.rng> >>> . >>> You may find all required specification files among >>> http://docs.oasis-open.org/office/v1.2/os/ >>> >>> The third is the problem interesting to us, see >>> http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2- >>> os-part1.html#element-style_master-page >>> Unfortunately, the spec does not show the order of elements, therefore >>> you need to look into the ODF XML RelaxNG grammar. >>> Within http://docs.oasis-open.org/office/v1.2/os/OpenDocumen >>> t-v1.2-os-schema.rng >>> you search for the element name (with ending quotation as there are some >>> longer names with this as prefix) style:master-page" and find: >>> <define name="style-master-page"> >>> <element name="style:master-page"> >>> <ref name="style-master-page-attlist"/> >>> <optional> >>> <ref name="style-header"/> >>> <optional> >>> <ref name="style-header-left"/> >>> </optional> >>> </optional> >>> <optional> >>> <ref name="style-footer"/> >>> <optional> >>> <ref name="style-footer-left"/> >>> </optional> >>> </optional> >>> Voila, first the header than the footer in strict order. See >>> relaxng.org/tutorial.html >>> In the file is it the other way around. >>> >>> Switch the elements and you may succeed! :) >>> >>> Have a nice week-end, >>> Svante >>> >>> >>> >>> >>> ᐧ >>> >>> 2018-01-13 3:49 GMT+01:00 Joseph D. Wagner <j...@josephdwagner.info>: >>> >>>> Thank you for your generous offer to help. >>>> >>>> The "works in libreoffice - not in word" file is the direct output from >>>> your library. >>>> >>>> The "works in both libreoffice and word" file is the output of when I >>>> take that file, fix it in word, and then save it again. (Oddly, word does >>>> something with the footer margin, and reopening this file in libreoffice >>>> reveals that the last line of the main area is cutoff by the footer. >>>> However, I'm hoping to ignore this.) >>>> >>>> I am using Word 2016. >>>> >>>> Thanks for all your time and effort. >>>> >>>> Joseph D. Wagner >>>> >>>> >>>> -----Original Message----- >>>> From: Svante Schubert [mailto:svante.schub...@gmail.com] >>>> Sent: Tuesday, January 9, 2018 1:50 AM >>>> To: odf-dev@incubator.apache.org >>>> Subject: Re: Trouble with Footer Font Size - Adding Page X of Y to >>>> Footer >>>> >>>> Hello Joeseph, >>>> >>>> the first interesting thing to mention from ODF perspective is that the >>>> text of a footer and header is part of the page style within the >>>> styles.xml. >>>> Therefore any automatic styles being used for header and footer are not >>>> within the content.xml, but styles.xml - and only those. >>>> Let us not discuss the pro and con of this design, let me simply state, >>>> that I am not a fan of it of the overall result :) >>>> >>>> In your example, it seems that the LibreOffice styles are not >>>> connecting to each other, ie. a32e835 at the paragraph and a2b0e5e at the >>>> paragraph style should be the same string, but this might be as well a copy >>>> paste error from different files. >>>> To alter the ODF styles, you might want to go a level deeper into the >>>> ODFDOM project <http://incubator.apache.org/o >>>> dftoolkit/odfdom/ProjectOverview.html>. >>>> Again take a look at the regression tests, where to find the desired >>>> elements. >>>> >>>> In general, every XML element has a generated DOM class with the prefix >>>> local name and either Attribute or Element suffix, for instance, >>>> TextSpanElement class. >>>> >>>> Hope it helps! >>>> >>>> Cheers, >>>> Svante >>>> ᐧ >>>> >>>> 2018-01-09 3:32 GMT+01:00 Joseph D. Wagner <j...@josephdwagner.info>: >>>> >>>> > I am trying to add a "Page X of Y" footer to the bottom of a text >>>> > document. I got everything working *EXCEPT* the font size. >>>> > >>>> > I wrote this code: >>>> > >>>> > // Adds Page X of Y to the footer >>>> > Font fontsmaller = new Font("Arial", >>>> > StyleTypeDefinitions.FontStyle.REGULAR, >>>> > 8); >>>> > Footer footer = doc.getFooter(); >>>> > Section footersection = footer.appendSection("Page Numbers"); >>>> > Paragraph footerparagraph = footersection.addParagraph("Pa >>>> > ge\u00A0"); >>>> > footerparagraph.setFont(fontsmaller); // Doesn't work here >>>> > either Fields.createCurrentPageNumberField(footerparagraph.getOdfEl >>>> ement()); >>>> > footerparagraph.appendTextContent("\u00A0of\u00A0"); >>>> > Fields.createPageCountField(footerparagraph.getOdfElement()); >>>> > footerparagraph.setFont(fontsmaller); // Doesn't work here >>>> > either >>>> > >>>> > It seems to work EXCEPT the part of changing the font size. In Word, >>>> > the font ends up being the default size of 12. (Works as expected in >>>> > LibreOffice.) >>>> > >>>> > Interesting, counterexample. It works when I set the font larger, >>>> > like 16, but it doesn't work when I set the font smaller, like 10 or >>>> 8. >>>> > >>>> > I performed a diff comparison on the output form odftoolkit(-) and the >>>> > output from Word(+). It seems the key difference is lines like these >>>> > in >>>> > styles.xml: >>>> > >>>> > - <style:style style:family="paragraph" style:name="a2b0e5e"> >>>> > - <style:paragraph-properties fo:text-align="center" >>>> > style:line-break="strict" style:punctuation-wrap="hanging" >>>> > style:text-autospace="ideograph-alpha" style:writing-mode="page"/> >>>> > - <style:text-properties fo:color="#000000" fo:country="US" >>>> > fo:font-size="10.0pt" fo:language="en" style:font-name="Courier New" >>>> > style:font-name-asian="Lucida Sans Unicode" >>>> > style:font-name-complex="Tahom a" >>>> > style:font-size-asian="12pt" style:font-size-complex="12pt"/> >>>> > + <style:style style:name="P2" style:parent-style-name="Normal" >>>> > style:family="paragraph"> >>>> > + <style:paragraph-properties fo:text-align="center"/> >>>> > + <style:text-properties style:font-name="Courier New"/> >>>> > + </style:style> >>>> > + <style:style style:name="T3" style:parent-style-name="Defau >>>> ltParagraphFont" >>>> > style:family="text"> >>>> > + <style:text-properties style:font-name="Courier New" >>>> > fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" >>>> > style:font-size-complex="8pt"/> >>>> > + </style:style> >>>> > + <style:style style:name="T4" style:parent-style-name="Defau >>>> ltParagraphFont" >>>> > style:family="text"> >>>> > + <style:text-properties style:font-name="Courier New" >>>> > fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" >>>> > style:font-size-complex="8pt"/> >>>> > + </style:style> >>>> > + <style:style style:name="T5" style:parent-style-name="Defau >>>> ltParagraphFont" >>>> > style:family="text"> >>>> > + <style:text-properties style:font-name="Courier New" >>>> > fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" >>>> > style:font-size-complex="8pt"/> >>>> > + </style:style> >>>> > + <style:style style:name="T6" style:parent-style-name="Defau >>>> ltParagraphFont" >>>> > style:family="text"> >>>> > + <style:text-properties style:font-name="Courier New" >>>> > fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" >>>> > style:font-size-complex="8pt"/> >>>> > </style:style> >>>> > >>>> > >>>> > - <style:footer> >>>> > - <text:section text:display="true" text:name="Page Numbers" >>>> > text:style-name="aec74e3"> >>>> > - <text:p text:style-name="a32e835">Page >>>> <text:span><text:page-number >>>> > style:num-format="" text:select-page="current"/> o f >>>> > </text:span><text:span><text:page-count >>>> style:num-format=""/></text:sp >>>> > an></text:p> >>>> > - </text:section> >>>> > - </style:footer> >>>> > >>>> > + <style:footer> >>>> > + <text:p text:style-name="Normal"> >>>> > + <text:span text:style-name="T3">Page </text:span> >>>> > + <text:span text:style-name="T4"> >>>> > + <text:page-number text:fixed="false">1</text:pag >>>> e-number> >>>> > + </text:span> >>>> > + <text:span text:style-name="T5"> of </text:span> >>>> > + <text:span text:style-name="T6"> >>>> > + <text:page-count>14</text:page-count> >>>> > + </text:span> >>>> > + </text:p> >>>> > + </style:footer> >>>> > >>>> > Unfortunately, I don't know what code I should write to force >>>> > odftoolkit to generate appropriate styles and text properties fields. >>>> > >>>> > Could someone please help me figure this one out? >>>> > >>>> > Thanks. >>>> > >>>> > Joseph D. Wagner >>>> > >>>> > >>>> >>> >>> >> >