827 VERIFY(::ReleaseDC(0, hDC));
828 return ret;
829
830 CATCH_BAD_ALLOC_RET(0);
831 }
832
833 /*
834 * Class: sun_awt_windows_WFontMetrics
835 * Method: charsWidth
836 * Signature: ([CII)I
837 */
838 JNIEXPORT jint JNICALL
839 Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self,
840 jcharArray str,
841 jint off, jint len)
842 {
843 TRY;
844
845 if (str == NULL) {
846 JNU_ThrowNullPointerException(env, "str argument");
847 return NULL;
848 }
849 if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) {
850 JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument");
851 return NULL;
852 }
853
854 jchar *strp = new jchar[len];
855 env->GetCharArrayRegion(str, off, len, strp);
856 jstring jstr = env->NewString(strp, len);
857 jint result = 0;
858 if (jstr != NULL) {
859 result = Java_sun_awt_windows_WFontMetrics_stringWidth(env, self,
860 jstr);
861 }
862 delete [] strp;
863 return result;
864
865 CATCH_BAD_ALLOC_RET(0);
866 }
867
868
869 /*
870 * Class: sun_awt_windows_WFontMetrics
871 * Method: bytesWidth
872 * Signature: ([BII)I
873 */
874 JNIEXPORT jint JNICALL
875 Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
876 jbyteArray str,
877 jint off, jint len)
878 {
879 TRY;
880
881 if (str == NULL) {
882 JNU_ThrowNullPointerException(env, "bytes argument");
883 return NULL;
884 }
885 if ((len < 0) || (off < 0) || (len + off > (env->GetArrayLength(str)))) {
886 JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument");
887 return NULL;
888 }
889 char *pStrBody = NULL;
890 jint result = 0;
891 try {
892 jintArray array = (jintArray)env->GetObjectField(self,
893 AwtFont::widthsID);
894 if (array == NULL) {
895 JNU_ThrowNullPointerException(env, "Can't access widths array.");
896 return NULL;
897 }
898 pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0);
899 if (pStrBody == NULL) {
900 JNU_ThrowNullPointerException(env, "Can't access str bytes.");
901 return NULL;
902 }
903 char *pStr = pStrBody + off;
904
905 jint *widths = NULL;
906 try {
907 widths = (jint *)env->GetPrimitiveArrayCritical(array, 0);
908 if (widths == NULL) {
909 env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
910 JNU_ThrowNullPointerException(env, "Can't access widths.");
911 return NULL;
912 }
913 for (; len; len--) {
914 result += widths[*pStr++];
915 }
916 } catch (...) {
917 if (widths != NULL) {
918 env->ReleasePrimitiveArrayCritical(array, widths, 0);
919 }
920 throw;
921 }
922
923 env->ReleasePrimitiveArrayCritical(array, widths, 0);
924
925 } catch (...) {
926 if (pStrBody != NULL) {
927 env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
928 }
929 throw;
930 }
931
|
827 VERIFY(::ReleaseDC(0, hDC));
828 return ret;
829
830 CATCH_BAD_ALLOC_RET(0);
831 }
832
833 /*
834 * Class: sun_awt_windows_WFontMetrics
835 * Method: charsWidth
836 * Signature: ([CII)I
837 */
838 JNIEXPORT jint JNICALL
839 Java_sun_awt_windows_WFontMetrics_charsWidth(JNIEnv *env, jobject self,
840 jcharArray str,
841 jint off, jint len)
842 {
843 TRY;
844
845 if (str == NULL) {
846 JNU_ThrowNullPointerException(env, "str argument");
847 return 0;
848 }
849 if ((len < 0) || (off < 0) || (len + off < 0) ||
850 (len + off > (env->GetArrayLength(str)))) {
851 JNU_ThrowArrayIndexOutOfBoundsException(env, "off/len argument");
852 return 0;
853 }
854
855 if (off == env->GetArrayLength(str)) {
856 return 0;
857 }
858
859 jchar *strp = new jchar[len];
860 env->GetCharArrayRegion(str, off, len, strp);
861 jstring jstr = env->NewString(strp, len);
862 jint result = 0;
863 if (jstr != NULL) {
864 result = Java_sun_awt_windows_WFontMetrics_stringWidth(env, self,
865 jstr);
866 }
867 delete [] strp;
868 return result;
869
870 CATCH_BAD_ALLOC_RET(0);
871 }
872
873
874 /*
875 * Class: sun_awt_windows_WFontMetrics
876 * Method: bytesWidth
877 * Signature: ([BII)I
878 */
879 JNIEXPORT jint JNICALL
880 Java_sun_awt_windows_WFontMetrics_bytesWidth(JNIEnv *env, jobject self,
881 jbyteArray str,
882 jint off, jint len)
883 {
884 TRY;
885
886 if (str == NULL) {
887 JNU_ThrowNullPointerException(env, "bytes argument");
888 return 0;
889 }
890 if ((len < 0) || (off < 0) || (len + off < 0) ||
891 (len + off > (env->GetArrayLength(str)))) {
892 JNU_ThrowArrayIndexOutOfBoundsException(env, "off or len argument");
893 return 0;
894 }
895
896 if (off == env->GetArrayLength(str)) {
897 return 0;
898 }
899
900 char *pStrBody = NULL;
901 jint result = 0;
902 try {
903 jintArray array = (jintArray)env->GetObjectField(self,
904 AwtFont::widthsID);
905 if (array == NULL) {
906 JNU_ThrowNullPointerException(env, "Can't access widths array.");
907 return 0;
908 }
909 pStrBody = (char *)env->GetPrimitiveArrayCritical(str, 0);
910 if (pStrBody == NULL) {
911 JNU_ThrowNullPointerException(env, "Can't access str bytes.");
912 return 0;
913 }
914 char *pStr = pStrBody + off;
915
916 jint *widths = NULL;
917 try {
918 widths = (jint *)env->GetPrimitiveArrayCritical(array, 0);
919 if (widths == NULL) {
920 env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
921 JNU_ThrowNullPointerException(env, "Can't access widths.");
922 return 0;
923 }
924 for (; len; len--) {
925 result += widths[*pStr++];
926 }
927 } catch (...) {
928 if (widths != NULL) {
929 env->ReleasePrimitiveArrayCritical(array, widths, 0);
930 }
931 throw;
932 }
933
934 env->ReleasePrimitiveArrayCritical(array, widths, 0);
935
936 } catch (...) {
937 if (pStrBody != NULL) {
938 env->ReleasePrimitiveArrayCritical(str, pStrBody, 0);
939 }
940 throw;
941 }
942
|