From f420df28233c26e555d203185fb292e83b94b8c3 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 6 Apr 2012 15:30:42 +0900 Subject: Add support for German umlaut and French ligatures flags Bug: 6202812 Change-Id: Ib4a7f96f6ef86c840069b15d04393f84d428c176 --- .../latin/makedict/BinaryDictInputOutput.java | 25 ++++++++++++++++------ .../latin/makedict/FusionDictionary.java | 10 ++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java index 820c0a59c..d22332116 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java @@ -17,6 +17,7 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; +import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; @@ -126,8 +127,9 @@ public class BinaryDictInputOutput { private static final int NOT_A_VERSION_NUMBER = -1; private static final int FIRST_VERSION_WITH_HEADER_SIZE = 2; - // No options yet, reserved for future use. - private static final int OPTIONS = 0; + // These options need to be the same numeric values as the one in the native reading code. + private static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1; + private static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4; // TODO: Make this value adaptative to content data, store it in the header, and // use it in the reading code. @@ -703,6 +705,14 @@ public class BinaryDictInputOutput { return bigramFlags; } + /** + * Makes the 2-byte value for options flags. + */ + private static final int makeOptionsValue(final DictionaryOptions options) { + return (options.mFrenchLigatureProcessing ? FRENCH_LIGATURE_PROCESSING_FLAG : 0) + + (options.mGermanUmlautProcessing ? GERMAN_UMLAUT_PROCESSING_FLAG : 0); + } + /** * Makes the flag value for a shortcut. * @@ -918,8 +928,9 @@ public class BinaryDictInputOutput { buffer[index++] = (byte) (0xFF & version); } // Options flags - buffer[index++] = (byte) (0xFF & (OPTIONS >> 8)); - buffer[index++] = (byte) (0xFF & OPTIONS); + final int options = makeOptionsValue(dict.mOptions); + buffer[index++] = (byte) (0xFF & (options >> 8)); + buffer[index++] = (byte) (0xFF & options); if (version >= FIRST_VERSION_WITH_HEADER_SIZE) { final int headerSizeOffset = index; index += 4; // Size of the header size @@ -1218,7 +1229,7 @@ public class BinaryDictInputOutput { } // Read options - source.readUnsignedShort(); + final int optionsFlags = source.readUnsignedShort(); final long headerSize; final HashMap options = new HashMap(); @@ -1240,7 +1251,9 @@ public class BinaryDictInputOutput { final Node root = readNode(source, headerSize, reverseNodeMapping, reverseGroupMapping); FusionDictionary newDict = new FusionDictionary(root, - new FusionDictionary.DictionaryOptions(options)); + new FusionDictionary.DictionaryOptions(options, + 0 != (optionsFlags & GERMAN_UMLAUT_PROCESSING_FLAG), + 0 != (optionsFlags & FRENCH_LIGATURE_PROCESSING_FLAG))); if (null != dict) { for (Word w : dict) { newDict.add(w.mWord, w.mFrequency, w.mShortcutTargets, w.mBigrams); diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java index 3515287b0..40bcfc3aa 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java +++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java @@ -239,13 +239,17 @@ public class FusionDictionary implements Iterable { * There are no options at the moment, so this class is empty. */ public static class DictionaryOptions { - final HashMap mAttributes; - public DictionaryOptions(final HashMap attributes) { + public final boolean mGermanUmlautProcessing; + public final boolean mFrenchLigatureProcessing; + public final HashMap mAttributes; + public DictionaryOptions(final HashMap attributes, + final boolean germanUmlautProcessing, final boolean frenchLigatureProcessing) { mAttributes = attributes; + mGermanUmlautProcessing = germanUmlautProcessing; + mFrenchLigatureProcessing = frenchLigatureProcessing; } } - public final DictionaryOptions mOptions; public final Node mRoot; -- cgit v1.2.3-83-g751a