< prev index next >

src/java.desktop/unix/native/common/awt/awt_Font.c

Print this page


   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 621             }
 622             (*env)->DeleteLocalRef(env, family);
 623             return (struct FontData *) NULL;
 624         }
 625         style = Style((*env)->GetIntField(env, font, fontIDs.style));
 626         oheight = height = (*env)->GetIntField(env, font, fontIDs.size);
 627 
 628         while (1) {
 629             jio_snprintf(fontSpec, sizeof(fontSpec), "-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
 630                          foundry,
 631                          name,
 632                          style,
 633                          height,
 634                          encoding);
 635 
 636             /*fprintf(stderr,"LoadFont: %s\n", fontSpec); */
 637             xfont = XLoadQueryFont(display, fontSpec);
 638 
 639             /* XXX: sometimes XLoadQueryFont returns a bogus font structure */
 640             /* with negative ascent. */
 641             if (xfont == (Font) NULL || xfont->ascent < 0) {
 642                 if (xfont != NULL) {
 643                     XFreeFont(display, xfont);
 644                 }
 645                 if (foundry != anyfoundry) {  /* Use ptr comparison here, not strcmp */
 646                     /* Try any other foundry before messing with the sizes */
 647                     foundry = anyfoundry;
 648                     continue;
 649                 }
 650                 /* We couldn't find the font. We'll try to find an */
 651                 /* alternate by searching for heights above and below our */
 652                 /* preferred height. We try for 4 heights above and below. */
 653                 /* If we still can't find a font we repeat the algorithm */
 654                 /* using misc-fixed as the font. If we then fail, then we */
 655                 /* give up and signal an error. */
 656                 if (above == below) {
 657                     above++;
 658                     height = oheight + above;
 659                 } else {
 660                     below++;
 661                     if (below > 4) {


 692                                        ptr_to_jlong(fdata));
 693                 }
 694                 (*env)->DeleteLocalRef(env, family);
 695                 return fdata;
 696             }
 697         }
 698         /* not reached */
 699     }
 700 }
 701 
 702 /*
 703  * Registered with the 2D disposer to be called after the Font is GC'd.
 704  */
 705 static void pDataDisposeMethod(JNIEnv *env, jlong pData)
 706 {
 707     struct FontData *fdata = NULL;
 708     int32_t i = 0;
 709     Display *display = XDISPLAY;
 710 
 711     AWT_LOCK();
 712     fdata = (struct FontData *)pData;
 713 
 714     if (fdata == NULL) {
 715         AWT_UNLOCK();
 716         return;
 717     }
 718 
 719     if (fdata->xfs != NULL) {
 720         XFreeFontSet(display, fdata->xfs);
 721     }
 722 
 723     /* AWT fonts are always "multifonts" and probably have been in
 724      * all post 1.0 releases, so this test for multi fonts is
 725      * probably not needed, and the singleton xfont is probably never used.
 726      */
 727     if (fdata->charset_num > 0) {
 728         for (i = 0; i < fdata->charset_num; i++) {
 729             free((void *)fdata->flist[i].xlfd);
 730             JNU_ReleaseStringPlatformChars(env, NULL,
 731                                            fdata->flist[i].charset_name);
 732             if (fdata->flist[i].load) {
   1 /*
   2  * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 621             }
 622             (*env)->DeleteLocalRef(env, family);
 623             return (struct FontData *) NULL;
 624         }
 625         style = Style((*env)->GetIntField(env, font, fontIDs.style));
 626         oheight = height = (*env)->GetIntField(env, font, fontIDs.size);
 627 
 628         while (1) {
 629             jio_snprintf(fontSpec, sizeof(fontSpec), "-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
 630                          foundry,
 631                          name,
 632                          style,
 633                          height,
 634                          encoding);
 635 
 636             /*fprintf(stderr,"LoadFont: %s\n", fontSpec); */
 637             xfont = XLoadQueryFont(display, fontSpec);
 638 
 639             /* XXX: sometimes XLoadQueryFont returns a bogus font structure */
 640             /* with negative ascent. */
 641             if (xfont == NULL || xfont->ascent < 0) {
 642                 if (xfont != NULL) {
 643                     XFreeFont(display, xfont);
 644                 }
 645                 if (foundry != anyfoundry) {  /* Use ptr comparison here, not strcmp */
 646                     /* Try any other foundry before messing with the sizes */
 647                     foundry = anyfoundry;
 648                     continue;
 649                 }
 650                 /* We couldn't find the font. We'll try to find an */
 651                 /* alternate by searching for heights above and below our */
 652                 /* preferred height. We try for 4 heights above and below. */
 653                 /* If we still can't find a font we repeat the algorithm */
 654                 /* using misc-fixed as the font. If we then fail, then we */
 655                 /* give up and signal an error. */
 656                 if (above == below) {
 657                     above++;
 658                     height = oheight + above;
 659                 } else {
 660                     below++;
 661                     if (below > 4) {


 692                                        ptr_to_jlong(fdata));
 693                 }
 694                 (*env)->DeleteLocalRef(env, family);
 695                 return fdata;
 696             }
 697         }
 698         /* not reached */
 699     }
 700 }
 701 
 702 /*
 703  * Registered with the 2D disposer to be called after the Font is GC'd.
 704  */
 705 static void pDataDisposeMethod(JNIEnv *env, jlong pData)
 706 {
 707     struct FontData *fdata = NULL;
 708     int32_t i = 0;
 709     Display *display = XDISPLAY;
 710 
 711     AWT_LOCK();
 712     fdata = (struct FontData *) jlong_to_ptr(pData);
 713 
 714     if (fdata == NULL) {
 715         AWT_UNLOCK();
 716         return;
 717     }
 718 
 719     if (fdata->xfs != NULL) {
 720         XFreeFontSet(display, fdata->xfs);
 721     }
 722 
 723     /* AWT fonts are always "multifonts" and probably have been in
 724      * all post 1.0 releases, so this test for multi fonts is
 725      * probably not needed, and the singleton xfont is probably never used.
 726      */
 727     if (fdata->charset_num > 0) {
 728         for (i = 0; i < fdata->charset_num; i++) {
 729             free((void *)fdata->flist[i].xlfd);
 730             JNU_ReleaseStringPlatformChars(env, NULL,
 731                                            fdata->flist[i].charset_name);
 732             if (fdata->flist[i].load) {
< prev index next >