Problem with polish chars

Developer
Sep 25, 2009 at 1:09 PM

Hello,

I'm not sure if it's a bug but at least it looks like it (or i am missing some option):

			Paragraph paragraphTextUzupelnianka = document.InsertParagraph();
			paragraphTextUzupelnianka
				.AppendLine(" akcji ").FontSize(9).Font(new FontFamily("Arial"))
				.Append(varAkcjeNazwa).Bold().FontSize(9).Font(new FontFamily("Arial"))
				.Append(" serii ").FontSize(9).Font(new FontFamily("Arial"))
				.Append(varAkcjeSeria).Bold().FontSize(9).Font(new FontFamily("Arial"))
				.Append(",").FontSize(9).Font(new FontFamily("Arial"))
				.AppendLine(" o wartości nominalnej ").FontSize(9).Font(new FontFamily("Arial"))
				.Append(varAkcjeNominal).Bold().FontSize(9).Font(new FontFamily("Arial"))
				.Append(" każda,").FontSize(9).Font(new FontFamily("Arial"));
			paragraphTextUzupelnianka.Alignment = Alignment.center;

Here's the code. The problem is with ż, ą, ę, ć, ł and any other polish char. While all of the text except mentioned letters is displayed with Arial,
polish letters seems to be displayed with Calibri (even thou they are in the middle of text).

This illustrate the problem better. Below text never gets changed to Arial.
			Paragraph paragraphTextUzupelnianka1 = document.InsertParagraph();
			paragraphTextUzupelnianka
				.AppendLine("ąęćłżźó").FontSize(9).Font(new FontFamily("Arial"));

Hope to get it fixed so I can continue my work :-) Thank You.


With regards,

MadBoy

Coordinator
Sep 26, 2009 at 9:21 AM
Hi MadBoy,

I am away traveling this weekend, I will take a look at this 'bug' when I return on Monday. Does this problem only happen when you use Polish characters?

regards,
Cathal
Developer
Sep 26, 2009 at 9:39 AM

Hello Cathal,

Yes all other text is correctly changed to Arial and with proper font size. Only polish chars are affected even thou they are inside the string that is
supposed to be converted to different font. I love your work as it allows me to create docs with ease and precision without much learning and advanced knowledge. Hope you can fix this.

With regards,


MadBoy

Coordinator
Sep 26, 2009 at 9:42 AM
Hi MadBoy,

I will try my very best to fix this on Monday. I do not understand why Polish text would be treated differently than English, but I will find out.

Cathal
Developer
Sep 28, 2009 at 3:24 PM

Hello,

Were you able to reproduce the issue?

With regards,

MadBoy

Coordinator
Sep 28, 2009 at 8:29 PM
Hi MadBoy,

I have been able to reproduce the problem, but I cannot figure out why this is happening. It works fine with English text, but it refuses to work with Polish.

Unfortunately I do not have anymore time to debug this issue tonight. This week is my first week back at college and I am very busy with assignments.

I will try and find time later in the week. If you make any break troughs, please let me know.
Cathal
Developer
Oct 22, 2009 at 2:04 PM

Hello coffeycathal,

Did you had any luck with it?

MadBoy

 

Coordinator
Oct 22, 2009 at 2:26 PM

Hi MadBoy,

I am sorry to say that I haven't had the time to investigate this bug. I have returned to college for my final year of "Computer Science & Software Engineering". Between lectures, study and my final year project I don't have any time to work on DocX. I am still answering questions on the forms, and making simple bug fixes, but I cannot afford to spend 6 hour blocks investigating deep bugs like this one.

I am sorry that this has inconvenienced you. As soon as I have finished my final year I will be dedicating all of my free time to DocX once again.

kind regards,
Cathal

Developer
Oct 22, 2009 at 8:11 PM

Hello coffeycathal,

 

Thank you for answer. It's no problem. You can't expect someone doing things for free to fix things with snap of fingers for everyone. Good luck on your last year. For now i am using only Calibri and will use it till it's fixed since i can't find better solution than yours ;-) I've tried to search for pdf / printing solutions as addition to your .docx and couldn't find anything that could be free and wouldn't need Word installed. Hope to see those features in some time after you're done with studies.

 

With regards,


MadBoy

Coordinator
Oct 23, 2009 at 8:18 AM
Hi MadBoy,
 
thank you for being so understanding. I too look forward to the day when DocX can handle to PDF conversion.
 
kind regards,
Cathal
Feb 24, 2010 at 11:29 AM

Hi MadBoy and Cathal,

On my first day using Docx I ran into this issue as well. Debugging a couple .docx files and looking at the source code helped me finding a workaround / bugfix for this. The XML tags that describe the font to be used will need to have some extra attributes to make sure that non-standard characters, such as Polish characters, are displayed in the correct font.

What I did was change the file Paragraph.cs. I have modified line 1665 (basically the body for the Font() method) as follows:

ApplyTextFormattingProperty(XName.Get("rFonts", DocX.w.NamespaceName), string.Empty,
	new[] {
		new XAttribute(XName.Get("ascii", DocX.w.NamespaceName), fontFamily.Name),
		new XAttribute(XName.Get("hAnsi", DocX.w.NamespaceName), fontFamily.Name),
		new XAttribute(XName.Get("cs", DocX.w.NamespaceName), fontFamily.Name),
	});

This way, two extra attributes (w:hAnsi and w:cs) are added to the output, making sure that Polish characters are to be displayed with the specified font. I am totally new to this XML specification, so I am not sure you might run into other problems, but so far it seems to work. At least for me :-)

Best regards,

Maurits

Developer
Feb 24, 2010 at 11:47 AM

Wow, great work! Thank you very much. I'll await for Cathal to release new version soon with the fix. Eventually if it will take too long i'll take the source and modify it myself. Otherwise it would be just too painful ;-)

Coordinator
Feb 24, 2010 at 12:48 PM
Hi Maurits,

thank you very much for taking the time to fix this bug. I am sure that lots of people will benefit from this fix. I will make sure that this fix is included into the next release of DocX and that you are credited for it.

kind regards,
Cathal
Feb 24, 2010 at 1:14 PM

Cathal,

No problem at all. I should thank you for taking the time to create this fine library! Good luck with your studies and looking forward to the next release.

Best regards,

Maurits

Developer
Jun 10, 2010 at 8:50 AM

Hello Cathal,

Is this issue resolved in your newest version or still pending?

 

With regards,

 

MadBoy

Coordinator
Jun 10, 2010 at 9:33 AM
Hi MadBoy,

this is still pending. I am however working on this right now, it should be easy enough to fix, I will get back to you in a few hours with an updated version of DocX.

kind regards,
Cathal
Coordinator
Jun 10, 2010 at 11:03 AM
MadBoy,

Maurits's fix was absolutely perfect. I have implemented it into the current working version of DocX. If you send me your email address I will send you the new dll.
I have tested it with the below code example, the outputted document contains Arial font as expected.

I would be grateful if you tested this and other examples on your side.
kind regards,
Cathal

Maurits if your reading this, I would like to say thank you. It is not very often that someone explorers the inner workings of DocX. 
Your solution to this bug was both elegant and succinct, your my kind of coder. If you ever find the time to further contribute to DocX I would be honored.

// Create a new document.
using (DocX document = DocX.Create("Test.docx"))
{
    // Create a paragraph
    Paragraph paragraphTextUzupelnianka1 = document.InsertParagraph();
    
    // Append some text to the Parragraph.
    paragraphTextUzupelnianka1.AppendLine("ąęćłżźó").FontSize(12).Font(new FontFamily("Arial")).Bold();

    // Save this document.
    document.Save();
}
Jun 22, 2010 at 7:14 AM

Cathal,

No problem at all! It was fun poking around in Word-generated XML to find out where things might go wrong.

So thank you for your kind words. I will try and see if I can improve on some other hacks I've made and help out a little more (after I've checked out the new version of course!)

Best regards,

Maurits.