diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt/ResourceTable.cpp | 46 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Canvas.java | 56 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Paint.java | 2 |
3 files changed, 82 insertions, 22 deletions
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index a2f085a..a84492d 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -12,6 +12,8 @@ #include <utils/ResourceTypes.h> #include <stdarg.h> +#include <set> + #define NOISY(x) //x status_t compileXmlFile(const sp<AaptAssets>& assets, @@ -2516,6 +2518,34 @@ ResourceFilter::match(const ResTable_config& config) return true; } +class entry_sort_t { +public: + sp<ResourceTable::Package> p; + sp<ResourceTable::Type> t; + sp<ResourceTable::ConfigList> c; + ResourceTable::ConfigDescription config; + sp<ResourceTable::Entry> e; + + entry_sort_t() { } + entry_sort_t( + sp<ResourceTable::Package> p, + sp<ResourceTable::Type> t, + sp<ResourceTable::ConfigList> c, + const ResourceTable::ConfigDescription &config, + sp<ResourceTable::Entry> e) + : p(p), t(t), c(c), config(config), e(e) { } + + bool operator < (const entry_sort_t &o) const { + int cmp; + if ((cmp = compare_type(config, o.config))) return cmp < 0; + if ((cmp = compare_type(t, o.t))) return cmp < 0; + if ((cmp = compare_type(e, o.e))) return cmp < 0; + if ((cmp = compare_type(c, o.c))) return cmp < 0; + if ((cmp = compare_type(p, o.p))) return cmp < 0; + return false; + } +}; + status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest) { ResourceFilter filter; @@ -2528,6 +2558,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest) size_t pi; bool useUTF8 = !bundle->getWantUTF16() && bundle->isMinSdkAtLeast(SDK_FROYO); + std::set< entry_sort_t > sortedEntries; // Iterate through all data, collecting all values (strings, // references, etc). @@ -2568,10 +2599,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest) continue; } e->setNameIndex(keyStrings.add(e->getName(), true)); - status_t err = e->prepareFlatten(&valueStrings, this); - if (err != NO_ERROR) { - return err; - } + sortedEntries.insert(entry_sort_t(p, t, c, config, e)); } } } @@ -2580,6 +2608,16 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest) p->setKeyStrings(keyStrings.createStringBlock()); } + for (std::set< entry_sort_t >::iterator ei=sortedEntries.begin(); ei!=sortedEntries.end(); ++ei) { + sp<Entry> e = ei->e; + status_t err = e->prepareFlatten(&valueStrings, this); + if (err != NO_ERROR) { + return err; + } + } + + sortedEntries.clear(); + ssize_t strAmt = 0; // Now build the array of package chunks. diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas.java b/tools/layoutlib/bridge/src/android/graphics/Canvas.java index d5d315e..d75ec79 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas.java @@ -49,6 +49,8 @@ import javax.microedition.khronos.opengles.GL; */ public class Canvas extends _Original_Canvas { + private static final char FIRST_RIGHT_TO_LEFT = '\u0590'; + private static final char LAST_RIGHT_TO_LEFT = '\u07b1'; private BufferedImage mBufferedImage; private final Stack<Graphics2D> mGraphicsStack = new Stack<Graphics2D>(); private final ILayoutLog mLogger; @@ -644,11 +646,8 @@ public class Canvas extends _Original_Canvas { getGraphics2d().scale(sx, sy); } - /* (non-Javadoc) - * @see android.graphics.Canvas#drawText(char[], int, int, float, float, android.graphics.Paint) - */ - @Override - public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { + + public void drawText(char[] text, int index, int count, float x, float y, Paint paint, boolean bidi) { // WARNING: the logic in this method is similar to Paint.measureText. // Any change to this method should be reflected in Paint.measureText Graphics2D g = getGraphics2d(); @@ -681,21 +680,29 @@ public class Canvas extends _Original_Canvas { FontInfo mainFont = fonts.get(0); int i = index; int lastIndex = index + count; + char[] bidiText; + if (bidi) { + bidiText=bidiProcess(text,index,count); + i=0; + lastIndex=count; + } else { + bidiText=text; + } while (i < lastIndex) { // always start with the main font. - int upTo = mainFont.mFont.canDisplayUpTo(text, i, lastIndex); + int upTo = mainFont.mFont.canDisplayUpTo(bidiText, i, lastIndex); if (upTo == -1) { // draw all the rest and exit. g.setFont(mainFont.mFont); - g.drawChars(text, i, lastIndex - i, (int)x, (int)y); + g.drawChars(bidiText, i, lastIndex - i, (int)x, (int)y); return; } else if (upTo > 0) { // draw what's possible g.setFont(mainFont.mFont); - g.drawChars(text, i, upTo - i, (int)x, (int)y); + g.drawChars(bidiText, i, upTo - i, (int)x, (int)y); // compute the width that was drawn to increase x - x += mainFont.mMetrics.charsWidth(text, i, upTo - i); + x += mainFont.mMetrics.charsWidth(bidiText, i, upTo - i); // move index to the first non displayed char. i = upTo; @@ -715,15 +722,15 @@ public class Canvas extends _Original_Canvas { // need to check that the font can display the character. We test // differently if the char is a high surrogate. - int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1; - upTo = fontInfo.mFont.canDisplayUpTo(text, i, i + charCount); + int charCount = Character.isHighSurrogate(bidiText[i]) ? 2 : 1; + upTo = fontInfo.mFont.canDisplayUpTo(bidiText, i, i + charCount); if (upTo == -1) { // draw that char g.setFont(fontInfo.mFont); - g.drawChars(text, i, charCount, (int)x, (int)y); + g.drawChars(bidiText, i, charCount, (int)x, (int)y); // update x - x += fontInfo.mMetrics.charsWidth(text, i, charCount); + x += fontInfo.mMetrics.charsWidth(bidiText, i, charCount); // update the index in the text, and move on i += charCount; @@ -736,13 +743,13 @@ public class Canvas extends _Original_Canvas { // in case no font can display the char, display it with the main font. // (it'll put a square probably) if (foundFont == false) { - int charCount = Character.isHighSurrogate(text[i]) ? 2 : 1; + int charCount = Character.isHighSurrogate(bidiText[i]) ? 2 : 1; g.setFont(mainFont.mFont); - g.drawChars(text, i, charCount, (int)x, (int)y); + g.drawChars(bidiText, i, charCount, (int)x, (int)y); // measure it to advance x - x += mainFont.mMetrics.charsWidth(text, i, charCount); + x += mainFont.mMetrics.charsWidth(bidiText, i, charCount); // and move to the next chars. i += charCount; @@ -755,6 +762,13 @@ public class Canvas extends _Original_Canvas { } /* (non-Javadoc) + * @see android.graphics.Canvas#drawText(char[], int, int, float, float, android.graphics.Paint) + */ + @Override + public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { + drawText(text, index, count, x, y, paint, true); + } + /* (non-Javadoc) * @see android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint) */ @Override @@ -1140,7 +1154,10 @@ public class Canvas extends _Original_Canvas { public void drawTextOnPath(char[] text, int index, int count, Path path, float offset, float offset2, Paint paint) { // TODO Auto-generated method stub - super.drawTextOnPath(text, index, count, path, offset, offset2, paint); + int i = 0; + char[] bidiText; + bidiText=bidiProcess(text,index,count); + super.drawTextOnPath(bidiText, i, count, path, offset, offset2, paint); } /* (non-Javadoc) @@ -1149,7 +1166,10 @@ public class Canvas extends _Original_Canvas { @Override public void drawTextOnPath(String text, Path path, float offset, float offset2, Paint paint) { // TODO Auto-generated method stub - super.drawTextOnPath(text, path, offset, offset2, paint); + int i = 0; + String bidiText; + bidiText=new String(bidiProcess(text.toCharArray(),0,text.length())); + super.drawTextOnPath(bidiText, path, offset, offset2, paint); } /* (non-Javadoc) diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java index 619ab30..d13b5fe 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint.java @@ -283,6 +283,8 @@ public class Paint extends _Original_Paint { mStyle = src.mStyle; mFlags = src.mFlags; + updateFontObject(); + super.set(src); } } |