Fix arabic

This commit is contained in:
Victor Shcherb 2012-08-26 23:25:00 +02:00
parent aa4398ca40
commit f949218eae
15 changed files with 155 additions and 11 deletions

View file

@ -15,5 +15,6 @@
<classpathentry kind="lib" path="lib/jsch-20120101.jar"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.18-bin.jar"/>
<classpathentry kind="lib" path="lib/junit-4.10.jar"/>
<classpathentry kind="lib" path="lib/icu4j-49_1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

View file

@ -0,0 +1,28 @@
package net.osmand.data;
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
public class ArabicShaper {
public static void main(String[] args) throws ArabicShapingException {
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE |
ArabicShaping.LENGTH_GROW_SHRINK);
String s = "אנשים 12";
// for (int i = 0; i < s.length(); i++) {
// System.out.println(s.charAt(i));
// }
Bidi bd = new Bidi(s.length(), s.length());
bd.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
System.out.println(bd.baseIsLeftToRight());
String r = as.shape(s);
// for (int i = 0; i < r.length(); i++) {
// System.out.println(r.charAt(i));
// }
System.out.println(r);
}
}

View file

@ -0,0 +1,89 @@
package net.osmand;
import org.apache.commons.logging.Log;
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
import com.ibm.icu.text.BidiRun;
public class Reshaper {
private final static Log LOG = LogUtil.getLog(Reshaper.class);
public static String reshape(String s) {
// if(true) {
// return s;
// }
try {
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK);
try {
s = as.shape(s);
} catch (ArabicShapingException e) {
LOG.error(e.getMessage(), e);
}
Bidi line = new Bidi(s.length(), s.length());
line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
byte direction = line.getDirection();
if (direction != Bidi.MIXED) {
// unidirectional
if(line.isLeftToRight()) {
return s;
} else {
char[] chs = new char[s.length()];
for(int i = 0; i< chs.length ; i++) {
chs[i] = s.charAt(chs.length - i - 1);
}
return new String(chs);
}
} else {
// // mixed-directional
int count = line.countRuns();
// if (styleRunCount <= 1) {
// int style = styleRuns[0].style;
// // iterate over directional runs
// for (i = 0; i < count; ++i) {
// run = line.getVisualRun(i);
// renderRun(text, run.getStart(), run.getLimit(),
// run.getDirection(), style);
// }
// }
StringBuilder res = new StringBuilder();
// iterate over both directional and style runs
for (int i = 0; i < count; ++i) {
BidiRun run = line.getVisualRun(i);
int st = run.getStart();
int e = run.getLimit();
int j = run.getDirection() == Bidi.LTR ? st : e - 1;
int l = run.getDirection() == Bidi.LTR ? e : st - 1;
boolean plus = run.getDirection() == Bidi.LTR;
while (j != l) {
res.append(s.charAt(j));
if (plus) {
j++;
} else {
j--;
}
}
}
return res.toString();
}
} catch (RuntimeException e) {
LOG.error(e.getMessage(), e);
return s;
}
}
public static void main(String[] args) {
// char[] c = new char[] {'א', 'ד','ם', ' ', '1', '2'} ;
// String reshape = "אדם";
char[] c = new char[] {'א', 'ד','ם'} ;
String reshape = reshape(new String(c));
for(int i=0; i < reshape.length(); i++) {
System.out.println(reshape.charAt(i));
}
}
}

BIN
OsmAnd/lib/icu4j-49_1.jar Normal file

Binary file not shown.

BIN
OsmAnd/libs/icu4j-49_1.jar Normal file

Binary file not shown.

View file

@ -9,7 +9,13 @@
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="tip_recent_changes_0_8_2_t">Changes in 0.8.2 :
\n\t* Improved Routing
\n\t* Dynamic map widgets
\n\t* Map settings moved to map screen
\n\t* Lock screen button with logging services
\n\t* Fixed Arabic, Kannada scripting and RTL languages
</string>
<string name="osmand_short_description_80_chars">Osmand is open source navigation application with raster/vector maps</string>
<string name="osmand_long_description_1000_chars">
Osmand (Open Street Maps Android)
@ -114,12 +120,6 @@ OsmAnd is still in active development and relies on "donations" based support to
<string name="show_cameras">Show speed cameras</string>
<string name="show_speed_limits">Show speed limits</string>
<string name="avoid_toll_roads">Avoid toll roads</string>
<string name="tip_recent_changes_0_8_2_t">Changes in 0.8.2 :
\n\t* Improved Routing
\n\t* Dynamic map widgets
\n\t* Map settings moved to map screen
\n\t* Lock screen button with logging services
</string>
<string name="continue_follow_previous_route_auto">Previous navigation was unfinished. Continue following it? (%1$s seconds)</string>
<string name="route_updated_loc_found">Route will be recalculated when location will be found</string>
<string name="osmand_parking_hours">Hours</string>

View file

@ -230,7 +230,7 @@ public class FavouritesActivity extends OsmandExpandableListActivity {
favoritesToDelete.remove(model);
}
} else {
QuickAction qa = new QuickAction(v);
final QuickAction qa = new QuickAction(v);
final OsmandSettings settings = getMyApplication().getSettings();
final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition);
String name = getString(R.string.favorite) + ": " + point.getName();
@ -238,7 +238,7 @@ public class FavouritesActivity extends OsmandExpandableListActivity {
OnClickListener onshow = new OnClickListener() {
@Override
public void onClick(View v) {
settings.SHOW_FAVORITES.set(true);
settings.SHOW_FAVORITES.set(true);
}
};
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), this,
@ -250,6 +250,7 @@ public class FavouritesActivity extends OsmandExpandableListActivity {
@Override
public void onClick(View v) {
editPoint(point);
qa.dismiss();
}
});
qa.addActionItem(edit);
@ -260,6 +261,7 @@ public class FavouritesActivity extends OsmandExpandableListActivity {
@Override
public void onClick(View v) {
deletePoint(point);
qa.dismiss();
}
});
qa.addActionItem(delete);

View file

@ -1073,7 +1073,7 @@ public class MapActivityActions implements DialogProvider {
menu.show();
}
public static void createDirectionsActions(QuickAction qa , final LatLon location, final Object obj, final String name, final int z, final Activity activity,
public static void createDirectionsActions(final QuickAction qa , final LatLon location, final Object obj, final String name, final int z, final Activity activity,
final boolean saveHistory, final OnClickListener onShow){
ActionItem showOnMap = new ActionItem();
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
@ -1088,6 +1088,7 @@ public class MapActivityActions implements DialogProvider {
app.getSettings().setMapLocationToShow( location.getLatitude(), location.getLongitude(),
z, saveHistory ? name : null, name, obj); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity);
qa.dismiss();
}
});
qa.addActionItem(showOnMap);
@ -1102,6 +1103,7 @@ public class MapActivityActions implements DialogProvider {
}
app.getSettings().setPointToNavigate(location.getLatitude(), location.getLongitude(), name);
MapActivity.launchMapActivityMoveToTop(activity);
qa.dismiss();
}
});
qa.addActionItem(setAsDestination);
@ -1117,6 +1119,7 @@ public class MapActivityActions implements DialogProvider {
}
app.getSettings().setPointToNavigate(location.getLatitude(), location.getLongitude(), true, name);
MapActivity.launchMapActivityMoveToTop(activity);
qa.dismiss();
}
});
qa.addActionItem(directionsTo);

View file

@ -516,7 +516,7 @@ public class SearchPOIActivity extends OsmandListActivity implements SensorEvent
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
QuickAction qa = new QuickAction(v);
final QuickAction qa = new QuickAction(v);
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, settings.usingEnglishNames());
String name = getString(R.string.poi)+" : " + poiSimpleFormat;
int z = Math.max(16, settings.getLastKnownMapZoom());

View file

@ -167,6 +167,10 @@ std::string RenderingContext::getTranslatedString(const std::string& src) {
return src;
}
std::string RenderingContext::getReshapedString(const std::string& src) {
return src;
}
inline double getPowZoom(float zoom){
if(zoom >= 0 && zoom - floor(zoom) < 0.05f){

View file

@ -195,6 +195,7 @@ public:
virtual bool interrupted();
virtual SkBitmap* getCachedBitmap(const std::string& bitmapResource);
virtual std::string getTranslatedString(const std::string& src);
virtual std::string getReshapedString(const std::string& src);
void setDefaultIconsDir(string path) {
defaultIconsDir = path;

View file

@ -349,7 +349,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_NativeLibrary_generateRende
////////// JNI Rendering Context //////////////
jclass jclass_JUnidecode;
jclass jclass_Reshaper;
jmethodID jmethod_JUnidecode_unidecode;
jmethodID jmethod_Reshaper_reshape;
jclass jclass_RenderingContext = NULL;
jfieldID jfield_RenderingContext_interrupted = NULL;
jfieldID jfield_RenderingContext_leftX = NULL;
@ -417,6 +419,8 @@ void loadJniRenderingContext(JNIEnv* env)
jclass_JUnidecode = findClass(env, "net/sf/junidecode/Junidecode");
jmethod_JUnidecode_unidecode = env->GetStaticMethodID(jclass_JUnidecode, "unidecode", "(Ljava/lang/String;)Ljava/lang/String;");
jclass_Reshaper = findClass(env, "net/osmand/Reshaper");
jmethod_Reshaper_reshape = env->GetStaticMethodID(jclass_Reshaper, "reshape", "(Ljava/lang/String;)Ljava/lang/String;");
jclass_RouteDataObject = findClass(env, "net/osmand/binary/RouteDataObject");
jclass_NativeRouteSearchResult = findClass(env, "net/osmand/NativeLibrary$NativeRouteSearchResult");
@ -666,3 +670,12 @@ std::string JNIRenderingContext::getTranslatedString(const std::string& name) {
return name;
}
std::string JNIRenderingContext::getReshapedString(const std::string& name) {
jstring n = this->env->NewStringUTF(name.c_str());
jstring translate = (jstring) this->env->CallStaticObjectMethod(jclass_Reshaper, jmethod_Reshaper_reshape, n);
std::string res = getString(this->env, translate);
this->env->DeleteLocalRef(translate);
this->env->DeleteLocalRef(n);
return res;
}

View file

@ -29,6 +29,8 @@ struct JNIRenderingContext : RenderingContext
virtual SkBitmap* getCachedBitmap(const std::string& bitmapResource);
virtual std::string getTranslatedString(const std::string& src);
virtual std::string getReshapedString(const std::string& src);
virtual bool interrupted();
virtual ~JNIRenderingContext(){}
};

View file

@ -208,6 +208,7 @@ void renderText(MapDataObject* obj, RenderingRuleSearchRequest* req, RenderingCo
if (it->second.length() > 0) {
std::string name = it->second;
name =rc->getTranslatedString(name);
name =rc->getReshapedString(name);
req->setInitialTagValueZoom(tag, value, rc->getZoom(), obj);
req->setIntFilter(req->props()->R_TEXT_LENGTH, name.length());
std::string tagName = it->first == "name" ? "" : it->first;