1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009,2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
28 /** |
28 /** |
29 * Implementation of LCDUI <code>Font</code> class. |
29 * Implementation of LCDUI <code>Font</code> class. |
30 */ |
30 */ |
31 public final class Font |
31 public final class Font |
32 { |
32 { |
33 |
33 /* |
34 /** |
34 * Point size value for the Medium LCDUI fonts. All |
|
35 * font sizes are relative to this value; |
|
36 */ |
|
37 private static final int MEDIUM_FONT_POINT_SIZE = 8; |
|
38 |
|
39 /** |
35 * System font face. |
40 * System font face. |
36 * |
41 * |
37 * @value for FACE_SYSTEM is 0. |
42 * @value for FACE_SYSTEM is 0. |
38 */ |
43 */ |
39 public static final int FACE_SYSTEM = 0; |
44 public static final int FACE_SYSTEM = 0; |
457 * @param length the length |
463 * @param length the length |
458 * @return the width |
464 * @return the width |
459 */ |
465 */ |
460 public int charsWidth(char[] c, int offset, int length) |
466 public int charsWidth(char[] c, int offset, int length) |
461 { |
467 { |
462 try |
468 try |
463 { |
469 { |
464 final String string = new String(c, offset, length); |
470 final String string = new String(c, offset, length); |
465 return stringWidth(string); |
471 return stringWidth(string); |
466 }catch (StringIndexOutOfBoundsException ex) |
472 }catch (StringIndexOutOfBoundsException ex) |
467 { |
473 { |
468 throw new ArrayIndexOutOfBoundsException(); |
474 throw new ArrayIndexOutOfBoundsException(); |
469 } |
475 } |
470 } |
476 } |
471 |
477 |
679 * @param size font's size |
685 * @param size font's size |
680 * @return font height |
686 * @return font height |
681 */ |
687 */ |
682 private static int mapSizeToHeight(int size) |
688 private static int mapSizeToHeight(int size) |
683 { |
689 { |
684 //retreive the system default height |
690 //maps relative to the medium font size |
685 int defHeight = getSystemFontData().getHeight(); |
691 //This is a static value on LCDUI because |
686 |
692 // Qt value was static and very small. |
687 if(size == Font.SIZE_SMALL) |
693 switch(size){ |
688 { |
694 case Font.SIZE_SMALL: |
689 //calculate the small size height as a ratio of system default medium size and round off the value to an integer |
695 return MEDIUM_FONT_POINT_SIZE - 1; |
690 return (int)Math.floor((defHeight * (3f/4)) + 0.5f); |
696 case Font.SIZE_LARGE: |
691 } |
697 return MEDIUM_FONT_POINT_SIZE + 1; |
692 else if(size == Font.SIZE_LARGE) |
698 default: |
693 { |
699 return MEDIUM_FONT_POINT_SIZE; |
694 //calculate the large height as a ratio of system default medium size and round off the value to an integer |
700 } |
695 return (int)Math.floor((defHeight * (4.5f/4)) + 0.5f); |
701 } |
696 } |
|
697 else |
|
698 { |
|
699 //return the system default height for medium size which is generally 12 but 7 in symbian for qt |
|
700 return defHeight; |
|
701 } |
|
702 } |
|
703 |
702 |
704 /** |
703 /** |
705 * Get LCDUI size from eSWT font height |
704 * Get LCDUI size from eSWT font height |
706 * |
705 * |
707 * @param height font's height |
706 * @param height font's height |
708 * @return font size |
707 * @return font size |
709 */ |
708 */ |
710 private static int mapHeightToSize(int height) |
709 private static int mapHeightToSize(int height) |
711 { |
710 { |
712 int defHeight = getSystemFontData().getHeight(); |
711 if(height < MEDIUM_FONT_POINT_SIZE) |
713 if(height < defHeight) |
|
714 { |
712 { |
715 return Font.SIZE_SMALL; |
713 return Font.SIZE_SMALL; |
716 } |
714 } |
717 else if(height > defHeight) |
715 else if(height > MEDIUM_FONT_POINT_SIZE) |
718 { |
716 { |
719 return Font.SIZE_LARGE; |
717 return Font.SIZE_LARGE; |
720 } |
718 } |
721 else |
719 else |
722 { |
720 { |