Free Support Forum - aspose.com

DefaultFont.LocaleId returns Incorrect value for Empty Document using Java

Hello,
I am curious to know the difference between following statements

  1. document.getStyles().getDefaultFont().getLocaleId()
  2. builder.getFont().getLocaleId() // Where builder is of same document

For some of my word document, both gives same value
For some of my documents both statements give different values

What locale do these statements returns?

regards

@sharma.vikash.mca

StyleCollection.DefaultFont property returns document default text formatting for style ‘Default Paragraph Font’. However, DocumentBuilder.Font property returns an object that represents current font formatting properties. Please move the cursor to some text into the document and check its font properties.

To check the locale of a style, you can use Font.LocaleId property as shown below.
document.getStyles().getByStyleIdentifier(StyleIdentifier.NORMAL).getFont().getLocaleId()

To check this property, please set the language of some text as ‘German’, move the document builder cursor to this text (Run node) and get localeId. It will return you the German locale ID.

1 Like

Thank you Tahir for the clear answer,

I understood both of your points. But in one of our scnerio, we have one document that is completely Empty. The default language of the document is English (as we can see at the bottom left in the blue strip in the MS Word). so the expected value of
document.getStyles().getDefaultFont().getLocaleId() is 1033 (code for English US).

But since there is no text in the document, what should we get for
builder.getFont().getLocaleId() ? For us, we are gettiing : 1036 (code for French ).

Let us know what do you think .

Program attached

Program1.zip (9.7 KB)

@sharma.vikash.mca

We have logged this problem in our issue tracking system as WORDSNET-21656. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Could you please ZIP and attach the following template document used for your document for further investigation?
C:\Documents and Settings\changch\Desktop\spain cert\Certificate template A-Spanish v1.65.dot

I am on Windows 10. The location is not available for me.

@sharma.vikash.mca

Thanks for sharing the detail. We will inform you via this forum thread once there is an update available on this issue.

@sharma.vikash.mca

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-21656) as ‘Not a Bug’.

Please resave your input DOC into DOCX format using MS Word. Then you can check following elements directly in styles.xml part of OOXML package:

  1. The Document.Styles.DefaultFont property corresponds to this element.
    <w:rPrDefault>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman" />
        <w:lang w:val="en-US" w:eastAsia="en-US" w:bidi="ar-SA" />
      </w:rPr>
    </w:rPrDefault>
  1. The Document.Styles[StyleIdentifier.Normal] corresponds to this element.
  <w:style w:type="paragraph" w:default="1" w:styleId="Normal">
    <w:name w:val="Normal" />
    <w:qFormat />
    <w:rPr>
      <w:lang w:val="fr-FR" w:eastAsia="fr-FR" />
    </w:rPr>
  </w:style>

As the DocumentBuilder returns current font formatting properties considering all styles which will be inherited by the current Run, then the properties of Normal style will be taken into resulted LanguageId.

Thank you for the replay and answer.