Difference between revisions of "Documentation/DevGuide/OfficeDev/Using Hyphenator"
m (1 revision(s)) |
m |
||
Line 9: | Line 9: | ||
The interface used for hyphenation is <idl>com.sun.star.linguistic2.XHyphenator</idl>. Accessing the hyphenator through the <code>LinguServiceManager</code> and initializing the <code>mxHyph</code> object is done by: | The interface used for hyphenation is <idl>com.sun.star.linguistic2.XHyphenator</idl>. Accessing the hyphenator through the <code>LinguServiceManager</code> and initializing the <code>mxHyph</code> object is done by: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
/** Get the Hyphenator to be used. | /** Get the Hyphenator to be used. | ||
*/ | */ | ||
Line 20: | Line 20: | ||
return mxHyph != null; | return mxHyph != null; | ||
} | } | ||
− | + | </source> | |
=== Relevant properties === | === Relevant properties === | ||
Line 56: | Line 56: | ||
The following example shows a word hypenated: | The following example shows a word hypenated: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
// maximum number of characters to remain before the hyphen | // maximum number of characters to remain before the hyphen | ||
// character in the resulting word of the hyphenation | // character in the resulting word of the hyphenation | ||
Line 71: | Line 71: | ||
+ " in " + xHyphWord.getHyphenatedWord() ); | + " in " + xHyphWord.getHyphenatedWord() ); | ||
} | } | ||
− | + | </source> | |
If the hyphenator implementation is working correctly, it reports a ''valid'' hyphenation position of 4 that is after the 'horse' part. Experiment with other values for nMaxLeading and other words. For example, if you set it to 4, no ''valid'' hyphenation position is found since there is no hyphenation position in the word 'horseback' before and including the 's'. | If the hyphenator implementation is working correctly, it reports a ''valid'' hyphenation position of 4 that is after the 'horse' part. Experiment with other values for nMaxLeading and other words. For example, if you set it to 4, no ''valid'' hyphenation position is found since there is no hyphenation position in the word 'horseback' before and including the 's'. | ||
Line 78: | Line 78: | ||
The example below shows querying for an alternative spelling. In some languages, for example German in the old (pre-reform) spelling, there are words where the spelling of changes when they are hyphenated at specific positions. To inquire about the existence of alternative spellings, the <code>queryAlternativeSpelling()</code> function is used: | The example below shows querying for an alternative spelling. In some languages, for example German in the old (pre-reform) spelling, there are words where the spelling of changes when they are hyphenated at specific positions. To inquire about the existence of alternative spellings, the <code>queryAlternativeSpelling()</code> function is used: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
//! Note: 'aProps' needs to have set 'IsGermanPreReform' to true! | //! Note: 'aProps' needs to have set 'IsGermanPreReform' to true! | ||
xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt", | xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt", | ||
Line 93: | Line 93: | ||
+ " in " + xHyphWord.getHyphenatedWord() ); | + " in " + xHyphWord.getHyphenatedWord() ); | ||
} | } | ||
− | + | </source> | |
The return types interface is the same as in the above example (<idl>com.sun.star.linguistic2.XHyphenatedWord</idl>). | The return types interface is the same as in the above example (<idl>com.sun.star.linguistic2.XHyphenatedWord</idl>). | ||
The next example demonstrates getting possible hyphenation positions. To determine all possible hyphenation positions in a word, do this: | The next example demonstrates getting possible hyphenation positions. To determine all possible hyphenation positions in a word, do this: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <source lang="java"> | |
XPossibleHyphens xPossHyph = mxHyph.createPossibleHyphens( "waterfall", aLocale, aEmptyProps ); | XPossibleHyphens xPossHyph = mxHyph.createPossibleHyphens( "waterfall", aLocale, aEmptyProps ); | ||
if (xPossHyph == null) | if (xPossHyph == null) | ||
Line 104: | Line 104: | ||
else | else | ||
System.out.println( xPossHyph.getPossibleHyphens() ); | System.out.println( xPossHyph.getPossibleHyphens() ); | ||
− | + | </source> | |
For a description of the return types interface, refer to <idl>com.sun.star.linguistic2.XPossibleHyphens</idl>. | For a description of the return types interface, refer to <idl>com.sun.star.linguistic2.XPossibleHyphens</idl>. | ||
{{PDL1}} | {{PDL1}} | ||
[[Category: Office Development]] | [[Category: Office Development]] |
Revision as of 16:43, 29 March 2008
The interface used for hyphenation is com.sun.star.linguistic2.XHyphenator. Accessing the hyphenator through the LinguServiceManager
and initializing the mxHyph
object is done by:
/** Get the Hyphenator to be used. */ public boolean GetHyph() throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException { if (mxLinguSvcMgr != null) mxHyph = mxLinguSvcMgr.getHyphenator(); return mxHyph != null; }
Relevant properties
The properties of the LinguProperties
service evaluated by the hyphenator are:
Hyphenating Properties of com.sun.star.linguistic2.LinguProperties | |
---|---|
IsIgnoreControlCharacters | Defines if control characters should be ignored or not. |
IsUseDictionaryList | Defines if the dictionary-list should be used or not. |
IsGermanPreReform | Defines if the new German spelling rules should be used for German language text or not. |
HyphMinLeading | The minimum number of characters of a hyphenated word to remain before the hyphenation character. |
HyphMinTrailing | The minimum number of characters of a hyphenated word to remain after the hyphenation character. |
HyphMinWordLength | The minimum length of a word to be hyphenated. |
Changing the values of these properties in the Lingu-Properties affect all subsequent calls to the hyphenator.
A valid hyphenation position is a possible one that meets the restrictions given by the HyphMinLeading
, HyphMinTrailing
and HyphMinWordLength
values.
For example, if HyphMinWordLength
is 7, "remove" does not have a valid hyphenation position. Also, this is the case when HyphMinLeading
is 3 or HyphMinTrailing
is 5.
The following example shows a word hypenated:
// maximum number of characters to remain before the hyphen // character in the resulting word of the hyphenation short nMaxLeading = 6; XHyphenatedWord xHyphWord = mxHyph.hyphenate( "horseback", aLocale, nMaxLeading , aEmptyProps ); if (xHyphWord == null) System.out.println( "no valid hyphenation position found" ); else { System.out.println( "valid hyphenation pos found at " + xHyphWord.getHyphenationPos() + " in " + xHyphWord.getWord() ); System.out.println( "hyphenation char will be after char " + xHyphWord.getHyphenPos() + " in " + xHyphWord.getHyphenatedWord() ); }
If the hyphenator implementation is working correctly, it reports a valid hyphenation position of 4 that is after the 'horse' part. Experiment with other values for nMaxLeading and other words. For example, if you set it to 4, no valid hyphenation position is found since there is no hyphenation position in the word 'horseback' before and including the 's'.
For a description of the return types interface, refer tocom.sun.star.linguistic2.XHyphenatedWord.
The example below shows querying for an alternative spelling. In some languages, for example German in the old (pre-reform) spelling, there are words where the spelling of changes when they are hyphenated at specific positions. To inquire about the existence of alternative spellings, the queryAlternativeSpelling()
function is used:
//! Note: 'aProps' needs to have set 'IsGermanPreReform' to true! xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt", new Locale("de","DE",""), (short)4, aProps ); if (xHyphWord == null) System.out.println( "no alternative spelling found at specified position." ); else { if (xHyphWord.isAlternativeSpelling()) System.out.println( "alternative spelling detectetd!" ); System.out.println( "valid hyphenation pos found at " + xHyphWord.getHyphenationPos() + " in " + xHyphWord.getWord() ); System.out.println( "hyphenation char will be after char " + xHyphWord.getHyphenPos() + " in " + xHyphWord.getHyphenatedWord() ); }
The return types interface is the same as in the above example (com.sun.star.linguistic2.XHyphenatedWord).
The next example demonstrates getting possible hyphenation positions. To determine all possible hyphenation positions in a word, do this:
XPossibleHyphens xPossHyph = mxHyph.createPossibleHyphens( "waterfall", aLocale, aEmptyProps ); if (xPossHyph == null) System.out.println( "no hyphenation positions found." ); else System.out.println( xPossHyph.getPossibleHyphens() );
For a description of the return types interface, refer to com.sun.star.linguistic2.XPossibleHyphens.
Content on this page is licensed under the Public Documentation License (PDL). |