javauis/lcdui_akn/javalcdui/src/Font.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CMIDToolkit.h"
       
    20 #include "MIDUtils.h"
       
    21 #include "javax_microedition_lcdui_Font.h"
       
    22 
       
    23 
       
    24 LOCAL_C void CreateL(CMIDToolkit* aToolkit, TInt* aHandle, TUint aStyle,
       
    25                      TUint aSize, TInt aFace, TBool aIsFreeSizeFont)
       
    26 {
       
    27     MMIDFont* font = aToolkit->ComponentFactory()->CreateFontL(
       
    28                          aStyle, aSize, aFace, aIsFreeSizeFont);
       
    29     CleanupDisposePushL(font);
       
    30     *aHandle = aToolkit->RegisterComponentL(font, NULL);
       
    31     CleanupPopComponent(font);
       
    32 }
       
    33 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Font__1create
       
    34 (JNIEnv*, jobject, jint aToolkit, jint aFace, jint aStyle, jint aSize,
       
    35  jboolean aIsFreeSizeFont)
       
    36 {
       
    37     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    38     TInt h = 0;
       
    39     TInt err = toolkit->ExecuteTrap(&CreateL, toolkit, &h,
       
    40                                     (TUint)aStyle, (TUint)aSize, (TInt)aFace, (TBool)aIsFreeSizeFont);
       
    41     return err == KErrNone ? h : err;
       
    42 }
       
    43 
       
    44 /*
       
    45  * Returns width of aString font in aFont.
       
    46  * Returned width is correctly scaled.
       
    47  */
       
    48 LOCAL_C TInt Width(MMIDFont* aFont,const TDesC* aString)
       
    49 {
       
    50     return aFont->Width(*aString);
       
    51 }
       
    52 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Font__1width
       
    53 (JNIEnv* aJni,jobject,jint aFont,jint aToolkit,jstring aString)
       
    54 {
       
    55     MMIDFont* font = MIDUnhandObject<MMIDFont>(aFont);
       
    56     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    57     RJString string(*aJni,aString);
       
    58     return toolkit->Execute(&Width,font,(const TDesC*)&string);
       
    59 }
       
    60 
       
    61 /*
       
    62  * Returns height of aFont font.
       
    63  * Returned height is correctly scaled.
       
    64  */
       
    65 LOCAL_C TInt Height(MMIDFont* aFont)
       
    66 {
       
    67     return aFont->Height();
       
    68 }
       
    69 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Font__1height(JNIEnv*,jobject,jint aFont,jint aToolkit)
       
    70 {
       
    71     MMIDFont* font = MIDUnhandObject<MMIDFont>(aFont);
       
    72     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    73     return toolkit->Execute(&Height,font);
       
    74 }
       
    75 
       
    76 /*
       
    77  * Returns position of baseline in aFont font.
       
    78  * Returned position is correctly scaled.
       
    79  */
       
    80 LOCAL_C TInt Baseline(MMIDFont* aFont)
       
    81 {
       
    82     return aFont->Baseline();
       
    83 }
       
    84 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Font__1baseline(JNIEnv*,jobject,jint aFont,jint aToolkit)
       
    85 {
       
    86     MMIDFont* font = MIDUnhandObject<MMIDFont>(aFont);
       
    87     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
    88     return toolkit->Execute(&Baseline,font);
       
    89 }
       
    90 
       
    91 LOCAL_C void GetFontSpecs(CMIDToolkit* aToolkit,TInt aFontSpecifier,TInt* aFace,TInt* aStyle,TInt* aSize)
       
    92 {
       
    93     SFontSpec fontSpec = aToolkit->Utils()->FontSpecifierSpecs(MMIDFont::TFontSpecifier(aFontSpecifier));
       
    94     *aFace = fontSpec.iFace;
       
    95     *aStyle = fontSpec.iStyle;
       
    96     *aSize = fontSpec.iSize;
       
    97 }
       
    98 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Font__1getFontSpec(JNIEnv*,jclass,jint aToolkit,jint aFontSpecifier)
       
    99 {
       
   100     CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit);
       
   101     TInt face;
       
   102     TInt style;
       
   103     TInt size;
       
   104     toolkit->ExecuteV(&GetFontSpecs,toolkit,(TInt)aFontSpecifier,&face,&style,&size);
       
   105     return (face<<16|style<<8|size);
       
   106 }