/** * Gets the total advance width of the given <tt>String</tt> in this * <tt>Font</tt>. * <p> * Java declaration: * <pre> * stringWidth(Ljava/lang/String;)I * </pre> * * @param str the <tt>String</tt> to be measured * * @return the total advance width of the <tt>String</tt> in pixels */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_Font_stringWidth) { int strLen; jint result = 0; KNI_StartHandles(2); KNI_DeclareHandle(str); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(1, str); KNI_GetParameterAsObject(0, thisObject); if ((strLen = KNI_GetStringLength(str)) == -1) { KNI_ThrowNew(midpNullPointerException, NULL); } else { int face, style, size; _JavaString *jstr; DECLARE_FONT_PARAMS(thisObject); SNI_BEGIN_RAW_POINTERS; jstr = GET_STRING_PTR(str); result = gx_get_charswidth(face, style, size, jstr->value->elements + jstr->offset, strLen); SNI_END_RAW_POINTERS; } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Gets the advance width of the specified character using this * <tt>Font</tt>. * <p> * Java declaration: * <pre> * charWidth(C)I * </pre> * * @param ch the character to be measured * * @return the total advance width in pixels (a non-negative value) */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_Font_charWidth) { jchar c = (jchar)KNI_GetParameterAsChar(1); int face, style, size; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(0, thisObject); DECLARE_FONT_PARAMS(thisObject); KNI_EndHandles(); KNI_ReturnInt(gx_get_charswidth(face, style, size, &c, 1)); }
//KNIEXPORT KNI_RETURNTYPE_INT //KNIDECL(javax_microedition_lcdui_Font_charsWidth) { JNIEXPORT jint JNICALL Java_org_thenesis_microbackend_ui_graphics_toolkit_gxj_GXJFont_charsWidth(JNIEnv *env, jobject font, jcharArray ch, jint offset, jint length) { int chLen; jint result = 0; if ((chLen = (*env)->GetArrayLength(env, ch)) == -1) { GXJ_ThrowException(env, "java/lang/NullPointerException", "Input char array is null"); } else if ((offset < 0) || (offset > chLen) || (length < 0) || (length > chLen) || ((offset + length) < 0) || ((offset + length) > chLen)) { GXJ_ThrowException(env, "java/lang/IndexOutOfBoundsException", ""); } else if (length != 0) { jint face, style, size; GXJFont_getFontType(env, font, &face, &style, &size); jchar *carr = (*env)->GetCharArrayElements(env, ch, NULL); result = gx_get_charswidth(face, style, size, &carr[offset], length); } return result; }
/** * Gets the combined advance width of multiple characters, starting at * the specified offset and for the specified number of characters using * this <tt>Font</tt>. * <p> * Java declaration: * <pre> * charsWidth([CII)I * </pre> * * @param ch the array of characters to be measured * @param offset the index of the first character to measure * @param length the number of characters to measure * * @return the total width of the character range in pixels */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_Font_charsWidth) { int length = (int)KNI_GetParameterAsInt(3); int offset = (int)KNI_GetParameterAsInt(2); int chLen; jint result = 0; KNI_StartHandles(2); KNI_DeclareHandle(ch); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(1, ch); KNI_GetParameterAsObject(0, thisObject); if ((chLen = KNI_GetArrayLength(ch)) == -1) { KNI_ThrowNew(midpNullPointerException, NULL); } else if ( (offset < 0) || (offset > chLen) || (length < 0) || (length > chLen) || ((offset + length) < 0) || ((offset + length) > chLen)) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); } else if (length != 0) { int face, style, size; DECLARE_FONT_PARAMS(thisObject); SNI_BEGIN_RAW_POINTERS; result = gx_get_charswidth(face, style, size, &(JavaCharArray(ch)[offset]), length); SNI_END_RAW_POINTERS; } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Gets the advance width of the specified character using this * <tt>Font</tt>. * <p> * Java declaration: * <pre> * charWidth(C)I * </pre> * * @param ch the character to be measured * * @return the total advance width in pixels (a non-negative value) */ JNIEXPORT jint JNICALL Java_org_thenesis_microbackend_ui_graphics_toolkit_gxj_GXJFont_charWidth(JNIEnv *env, jobject font, jchar c) { jint face, style, size; GXJFont_getFontType(env, font, &face, &style, &size); return gx_get_charswidth(face, style, size, &c, 1); }