Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1849

Re: Actual width of unicode chracters.

From Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups comp.lang.java.help
Subject Re: Actual width of unicode chracters.
Date 2012-06-13 00:00 -0400
Organization A noiseless patient Spider
Message-ID <jr939r$dci$1@dont-email.me> (permalink)
References <jr8tid$64v$1@tnews.hananet.net>

Show all headers | View raw


On 6/12/2012 10:23 PM, Young wrote:
>    I am trying to write a class that draws tables in console mode. Korean
> character takes two space width for one character. When I count length of
> a string having numbers and Korean Characters together, I cannot get
> correct width. In result, I cannot align vertical line right.
>    So, I have wrote a new method, countWidth().
>
> 	private boolean isEnglish(Char s) {
> 		if (s < 256) {
> 			return true;
> 		} else {
> 			return false;
> 		}
>
>    However, this would work properly when I have English and Korean in
> string variables. How would I know how many character spaces in console?
> Thank you.

Unicode characters cannot be neatly divided into "one space" and "two 
space" characters. The string represented "a`" (substitute the combining 
diacritic instead of a backtick) is two characters wide but generally 
occupies as much space as an `a'. Since the rendering of a character 
depends on its context, you can only accurate measure the size of text 
by computing the size of the entire text. Even then, you still need to 
know the font being used: in particular, letters like `l' or `m' have 
extremely variable widths depending on the font.

However, since you said you're using console mode, I presume you intend 
to mean that you're using a font that you know to be "fixed-width." In 
that case, you could probably get away with dividing the range of 
Unicode text into diacritics (which take up no extra space), halfwidth 
(taking the space normally associated with the Latin alphabet) or 
fullwidth (taking up two characters). 
<http://docs.oracle.com/javase/6/docs/api/java/awt/im/InputSubset.html> 
gives several subsets which are probably sufficient for most input that 
you'd care about, but I leave the actual code to do the mapping up to you.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Actual width of unicode chracters. Young <ycp101@gmail.com> - 2012-06-13 02:23 +0000
  Re: Actual width of unicode chracters. Roedy Green <see_website@mindprod.com.invalid> - 2012-06-12 20:42 -0700
  Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-12 20:45 -0700
    Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 00:58 -0700
      Re: Actual width of unicode chracters. Young <ycp101@gmail.com> - 2012-06-13 08:30 +0000
        Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 08:45 -0700
        Re: Actual width of unicode chracters. Lew <lewbloch@gmail.com> - 2012-06-13 14:14 -0700
          Re: Actual width of unicode chracters. Steven Simpson <ss@domain.invalid> - 2012-06-14 08:06 +0100
            Re: Actual width of unicode chracters. "mayeul.marguet" <mayeul.marguet@free.fr> - 2012-06-14 10:26 +0200
              Re: Actual width of unicode chracters. "Peter J. Holzer" <hjp-usenet2@hjp.at> - 2012-06-14 15:32 +0200
                Re: Actual width of unicode chracters. "mayeul.marguet" <mayeul.marguet@free.fr> - 2012-06-14 16:47 +0200
                Re: Actual width of unicode chracters. "Peter J. Holzer" <hjp-usenet2@hjp.at> - 2012-06-16 20:39 +0200
  Re: Actual width of unicode chracters. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-06-13 00:00 -0400
  Re: Actual width of unicode chracters. markspace <-@.> - 2012-06-13 00:24 -0700
  Re: Actual width of unicode chracters. Steven Simpson <ss@domain.invalid> - 2012-06-13 10:24 +0100

csiph-web