2

Help folks, I am developing an app for android and need to use only 1 weird unicode character:

\u0180 - ƀ

My question is:

is it possible to simply insert this char into an existing font or any other way than to include a huge 5-10 mb font into the application that supports this unicode char? Please any ideas, any links, some directions. Thanks folks.

Gutyn
  • 461
  • 4
  • 22
  • As far as real letters go, there are no "weird" characters in unicode. What you call weird, someone else will call "just a normal letter in my written language", so when you're asking about is an unsupported unicode character. Not a weird one. Also if you want immediate help, add more details. Where have you searched already, what have you tried, why didn't that work, etc. Don't just suggest you've not done any research yet while expecting immediate answers =) – Mike 'Pomax' Kamermans Aug 21 '15 at 20:17

1 Answers1

2

Keywords to google around: Typeface, MetricAffectingSpan, SpannableString.

You don't have to include the whole set of characters you don't need. You can create your own typeface containing the only character with a code of your choice. And then you can use this typeface to span strings that contain that character.

Assuming you have a TTF font file called custom_font with your character, you can put it in your assets/fonts folder and create a typeface object:

Typeface customTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/custom_font.ttf");

and then you can span your special character across the string (assuming you don't know its exact position beforehand):

SpannableStringBuilder resultSpan = new SpannableStringBuilder(yourString);

for (int i = 0; i < resultSpan.length(); i++) {
  if (resultSpan.charAt(i) == '\u0180') {
    CustomTypefaceSpan typefaceSpan = new CustomTypefaceSpan(customTypeface);
    resultSpan.setSpan(typefaceSpan, i, i + 1, 0);
  }
}

SpannableStringBuilder implements CharSequence, so your TextViews and EditTexts will gladly accept it.

You can take the implementation of CustomTypefaceSpan from this answer.

Community
  • 1
  • 1
SqueezyMo
  • 1,606
  • 2
  • 21
  • 34
  • Yes I tried different fonts but I did not know you can span the char set, thank you friend. – Gutyn Aug 21 '15 at 20:22