< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1998, 2015, 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


 788         closeFontConfig(libfontconfig, JNI_FALSE);
 789         return NULL;
 790     }
 791 
 792     /* Make calls into the fontconfig library to build a search for
 793      * outline fonts, and to get the set of full file paths from the matches.
 794      * This set is returned from the call to FcFontList(..)
 795      * We allocate an array of char* pointers sufficient to hold all
 796      * the matches + 1 extra which ensures there will be a NULL after all
 797      * valid entries.
 798      * We call FcStrDirname strip the file name from the path, and
 799      * check if we have yet seen this directory. If not we add a pointer to
 800      * it into our array of char*. Note that FcStrDirname returns newly
 801      * allocated storage so we can use this in the return char** value.
 802      * Finally we clean up, freeing allocated resources, and return the
 803      * array of unique directories.
 804      */
 805     pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
 806     objset = (*FcObjectSetBuild)(FC_FILE, NULL);
 807     fontSet = (*FcFontList)(NULL, pattern, objset);




 808     fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
 809     for (f=0; f < fontSet->nfont; f++) {
 810         FcChar8 *file;
 811         FcChar8 *dir;
 812         if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
 813                                   FcResultMatch) {
 814             dir = (*FcStrDirname)(file);
 815             found = 0;
 816             for (i=0;i<numdirs; i++) {
 817                 if (strcmp(fontdirs[i], (char*)dir) == 0) {
 818                     found = 1;
 819                     break;
 820                 }
 821             }
 822             if (!found) {
 823                 fontdirs[numdirs++] = (char*)dir;
 824             } else {
 825                 free((char*)dir);
 826             }
 827         }
 828     }



 829 
 830     /* Free memory and close the ".so" */
 831     (*FcFontSetDestroy)(fontSet);
 832     (*FcPatternDestroy)(pattern);
 833     closeFontConfig(libfontconfig, JNI_TRUE);
 834     return fontdirs;
 835 }
 836 
 837 /* These are copied from sun.awt.SunHints.
 838  * Consider initialising them as ints using JNI for more robustness.
 839  */
 840 #define TEXT_AA_OFF 1
 841 #define TEXT_AA_ON  2
 842 #define TEXT_AA_LCD_HRGB 4
 843 #define TEXT_AA_LCD_HBGR 5
 844 #define TEXT_AA_LCD_VRGB 6
 845 #define TEXT_AA_LCD_VBGR 7
 846 
 847 JNIEXPORT jint JNICALL
 848 Java_sun_font_FontConfigManager_getFontConfigAASettings
 849 (JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
 850 
 851     FcNameParseFuncType FcNameParse;


   1 /*
   2  * Copyright (c) 1998, 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


 788         closeFontConfig(libfontconfig, JNI_FALSE);
 789         return NULL;
 790     }
 791 
 792     /* Make calls into the fontconfig library to build a search for
 793      * outline fonts, and to get the set of full file paths from the matches.
 794      * This set is returned from the call to FcFontList(..)
 795      * We allocate an array of char* pointers sufficient to hold all
 796      * the matches + 1 extra which ensures there will be a NULL after all
 797      * valid entries.
 798      * We call FcStrDirname strip the file name from the path, and
 799      * check if we have yet seen this directory. If not we add a pointer to
 800      * it into our array of char*. Note that FcStrDirname returns newly
 801      * allocated storage so we can use this in the return char** value.
 802      * Finally we clean up, freeing allocated resources, and return the
 803      * array of unique directories.
 804      */
 805     pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
 806     objset = (*FcObjectSetBuild)(FC_FILE, NULL);
 807     fontSet = (*FcFontList)(NULL, pattern, objset);
 808     if (fontSet == NULL) {
 809         /* FcFontList() may return NULL if fonts are not installed. */
 810         fontdirs = NULL;
 811     } else {
 812         fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
 813         for (f=0; f < fontSet->nfont; f++) {
 814             FcChar8 *file;
 815             FcChar8 *dir;
 816             if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
 817                                       FcResultMatch) {
 818                 dir = (*FcStrDirname)(file);
 819                 found = 0;
 820                 for (i=0;i<numdirs; i++) {
 821                     if (strcmp(fontdirs[i], (char*)dir) == 0) {
 822                         found = 1;
 823                         break;
 824                     }
 825                 }
 826                 if (!found) {
 827                     fontdirs[numdirs++] = (char*)dir;
 828                 } else {
 829                     free((char*)dir);
 830                 }
 831             }
 832         }
 833         /* Free fontset if one was returned */
 834         (*FcFontSetDestroy)(fontSet);
 835     }
 836 
 837     /* Free memory and close the ".so" */

 838     (*FcPatternDestroy)(pattern);
 839     closeFontConfig(libfontconfig, JNI_TRUE);
 840     return fontdirs;
 841 }
 842 
 843 /* These are copied from sun.awt.SunHints.
 844  * Consider initialising them as ints using JNI for more robustness.
 845  */
 846 #define TEXT_AA_OFF 1
 847 #define TEXT_AA_ON  2
 848 #define TEXT_AA_LCD_HRGB 4
 849 #define TEXT_AA_LCD_HBGR 5
 850 #define TEXT_AA_LCD_VRGB 6
 851 #define TEXT_AA_LCD_VBGR 7
 852 
 853 JNIEXPORT jint JNICALL
 854 Java_sun_font_FontConfigManager_getFontConfigAASettings
 855 (JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
 856 
 857     FcNameParseFuncType FcNameParse;


< prev index next >