コード例 #1
0
ファイル: widget.c プロジェクト: cgbarnwell/mvpmc
int
mvpw_font_height(int font, bool utf8)
{
	GR_FONT_INFO finfo;

	GrGetFontInfo(font, &finfo);

	return finfo.height;
}
コード例 #2
0
ファイル: srvnet.c プロジェクト: koujinogaku/helloos
static void
GrGetFontInfoWrapper(void *r)
{
	nxGetFontInfoReq *req = r;
	GR_FONT_INFO      fi;

	GrGetFontInfo(req->fontid, &fi);
	GsWriteType(current_fd,GrNumGetFontInfo);
	GsWrite(current_fd, &fi, sizeof(fi));
}
jboolean
Java_java_awt_Toolkit_fntIsWideFont( JNIEnv* env, jclass clazz, jobject _jfont )
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);

	return (fontinfo.lastchar < 256 )?JNI_FALSE:JNI_TRUE;
}
jint
Java_java_awt_Toolkit_fntGetHeight( JNIEnv* env, jclass clazz, jobject _jfont )
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);

	return fontinfo.height;
}
コード例 #5
0
ファイル: info.c プロジェクト: LucidOne/Rovio
int main()
{
	GR_SCREEN_INFO  si;
	GR_FONT_INFO    fi;
	GR_GC_INFO      gi;
	GR_FONT         fonts;
	int             x, y;

	GrOpen();
	GrGetScreenInfo(&si);

	printf("rows = %d\n", si.rows);
	printf("cols = %d\n", si.cols);
	printf("bpp = %d\n", si.bpp);
	printf("planes = %d\n", si.planes);
	printf("ncolors = %d\n", si.ncolors);
	printf("buttons = 0x%x\n", si.buttons);
	printf("modifiers = 0x%x\n", si.modifiers);
	printf("fonts = %d\n", si.fonts);

	getch();

	for(fonts = 0; fonts < si.fonts; fonts++) {
/*		if(!GrGetFontInfo(fonts, &fi)) { */
		GrGetFontInfo(fonts, &fi);
		if(1) {
			printf("\nfont = %d\n", fi.font);
			printf("height = %d\n", fi.height);
			printf("maxwidth = %d\n", fi.maxwidth);
			printf("baseline = %d\n", fi.baseline);
			printf("fixed = %s\n", fi.fixed ? "TRUE" : "FALSE");
			printf("widths =\n");
			for(y = 0; y != 3; y++) {
				for(x = 0; x != 7; x++)
					printf("%2d", fi.widths[x * y]);
				printf("\n");

				getch();

			}
		}
	}

	getch();

	GrClose();
}
jint 
Java_java_awt_Toolkit_fntBytesWidth(JNIEnv *envP, jclass k, jobject _jfont, 
jbyteArray _jbytes, jint off, jint len) 
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;
	jboolean isCopy;
	int w;
	int n,i;
	jbyte *jb;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	if ( _jbytes == NULL) {
		SignalError("java.lang.NullPointerException", "no byte array ");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);

	n = (*envP)->GetArrayLength(envP, _jbytes);
	if ( n < ( off + len )) {
		return 0;
	}
	if ( fontinfo.fixed ) {
		return len * fontinfo.maxwidth;
	} else {
		jb = (*envP)->GetByteArrayElements(envP, _jbytes, &isCopy);
		if ( jb == NULL ) {
			SignalError("java.lang.OutOfMemoryError","can't alocate byte array");
			return 0;
		}
		w = 0;
		for( i = off; i < off + len; i++ ) {
			if ( fontinfo.lastchar < jb[i] ) {
				return 0;
			}
			w += fontinfo.widths[(unsigned int)jb[i]];
		}
		(*envP)->ReleaseByteArrayElements(envP, _jbytes, jb, 0);
	}

	return w;
}
jint
Java_java_awt_Toolkit_fntCharsWidth ( JNIEnv* envP, jclass clazz, jobject _jfont, jcharArray _jchars, jint off, jint len )
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;
	jboolean  isCopy;
	jchar *jc;
	int n, w, i;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	if ( _jchars == NULL ) {
		SignalError("java.lang.NullPointerException", "no char array object");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);
	
	n = (*envP)->GetArrayLength( envP, _jchars);
	if ( n < ( off + len )) {
		return 0;
	}

	if ( fontinfo.fixed ) {
		return len * fontinfo.maxwidth;
	} else {
		jc = (*envP)->GetCharArrayElements(envP, _jchars, &isCopy);
		if ( jc == NULL ) {
			SignalError("java.lang.OutOfMemoryError", "can't alocate char array");
			return 0;
		}
		w = 0;
		for( i = off; i < off + len; i++ ) {
			if ( fontinfo.lastchar < jc[i] ) {
				return 0;
			}
			w += fontinfo.widths[(unsigned int)jc[i]];
		}
		(*envP)->ReleaseCharArrayElements( envP, _jchars, jc, JNI_ABORT);
	}

	return w;
}
コード例 #8
0
ファイル: widget.c プロジェクト: cgbarnwell/mvpmc
int
mvpw_font_width(int font, char *str, bool utf8)
{
	GR_FONT_INFO finfo;
	int i, w = 0;

	GrGetFontInfo(font, &finfo);

	if (utf8) {
		utf8_for_each2(str, &accumulate_width,
			       (void *)&finfo, (void *)&w);
	} else {
		for (i=0; i<strlen(str); i++)
			w += finfo.widths[(int)str[i]];
	}

	return w;
}
jobject
Java_java_awt_Toolkit_fntGetWidths(JNIEnv* envP, jclass clazz, jobject _jfont )
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;
	jintArray widths;
	jint *jw;
	jboolean isCopy;
	int i;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);

	widths = (*envP)->NewIntArray(envP, fontinfo.lastchar + 1);
	if ( widths == NULL ) {
		SignalError("java.lang.OutOfMemoryError", "can't alocate int array");
		return 0;
	}
	jw = (*envP)->GetIntArrayElements(envP, widths, &isCopy);
	if ( jw == NULL ) {
		SignalError("java.lang.OutOfMemoryError","can't alocate int array");
		return 0;
	}


	if ( fontinfo.fixed ) {
		for ( i = fontinfo.firstchar ; i <= fontinfo.lastchar ; i++ ) {
			jw[i] = fontinfo.maxwidth;
		}
	} else {
		for ( i = fontinfo.firstchar ; i <= fontinfo.lastchar ; i++ ) {
			jw[i] = fontinfo.widths[i];
		}
	}

	(*envP)->ReleaseIntArrayElements(envP, widths, jw, 0);

	return widths;
}
jint
Java_java_awt_Toolkit_fntCharWidth( JNIEnv* envP, jclass clazz, jobject _jfont, jchar jChar )
{
	GR_FONT_ID fontid;
	GR_FONT_INFO fontinfo;

	if ( _jfont == NULL) {
		SignalError("java.lang.NullPointerException", "no font object");
		return 0;
	}
	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);

	if ( fontinfo.lastchar < jChar ) {
		return 0;
	} else if ( fontinfo.fixed ) {
		return fontinfo.maxwidth;
	} else {
		return fontinfo.widths[(unsigned int)jChar];
	}
}
jint
Java_java_awt_Toolkit_fntStringWidth( JNIEnv* env, jclass clazz, jobject _jfont, jstring _jstr )
{
	jboolean isCopy;
	const jchar    *jc;
	int      len;
	int      i,w;
	GR_FONT_INFO fontinfo;
	GR_FONT_ID fontid;

	if (( _jfont == NULL) || (_jstr == NULL)) {
		SignalError("java.lang.NullPointerException", "no object");
		return 0;
	}

	jc = (*env)->GetStringChars( env, _jstr, &isCopy);
	if ( jc == NULL ) {
		SignalError("java.lang.OutOfMemoryError", "can't alocate chars");
		return 0;
	}
	len = (*env)->GetStringLength( env, _jstr);

	fontid = (GR_FONT_ID)_jfont;
	GrGetFontInfo(fontid,&fontinfo);
	w = 0;
	for( i = 0 ; i < len ; i++ ) {
		unsigned int index;
		index = (unsigned int)jc[i];
		if (( index < fontinfo.firstchar ) ||( index > fontinfo.lastchar )) {
			SignalError("java.lang.InternalError", "font id error");
		}
		w += fontinfo.widths[index];
	}

	(*env)->ReleaseStringChars( env, _jstr, jc);
	return w;
}
コード例 #12
0
ファイル: ecos_init.c プロジェクト: EPiCS/reconos_v2
void
ecos_nx_init(CYG_ADDRWORD data)
{
    GR_SCREEN_INFO	si;		/* window information */
    GR_FONT_INFO	fi;		/* font information */
    GR_WINDOW_ID	mainwid;	/* main window id */
    GR_WM_PROPERTIES    props;
    GR_GC_ID		gct = 0;
#if 0
    NWIDGET             *w;
    NBUTTON             *b;
    NTEXTFIELD          *t;
#endif

    cyg_thread_delay(50);
    INIT_PER_THREAD_DATA();

    test_file_io();

    if(GrOpen() < 0) {
        fprintf(stderr, "Couldn't connect to Nano-X server\n");
        exit(1);
    }

#if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
    GrSetPortraitMode(MWPORTRAIT_RIGHT);
#endif
    
    GrGetScreenInfo(&si);
    GrGetFontInfo(0, &fi);

#if 1
    mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows,
                          0, RED, WHITE);

    props.flags = GR_WM_FLAGS_PROPS;
    props.props = GR_WM_PROPS_BORDER;
    GrSetWMProperties(mainwid, &props);

    GrMapWindow(mainwid);
    GrFlush();
    cyg_thread_delay(50);

    gct = GrNewGC();
    GrSetGCForeground(gct, WHITE);

#ifdef CYGPKG_IO_FILEIO
    {
        struct stat         stat_data;
        if (0 == stat("/redhat.logo", &stat_data)) {
            GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0);
        }
    }
#endif

#if (defined CYGPKG_HAL_ARM) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
    // Touch sensitive screen calibration, only relevant on some
    // platforms.
    GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL));
    GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP);
    GrFlush();
    printf("Tap all four corners\n");
    cyg_thread_delay(10*100);
#endif    

#else
    n_init_button_class();
    n_init_textfield_class();

    w = NEW_NOBJECT(widget);
    n_widget_init(w, 0);    
    n_widget_resize(w, si.cols - 10, si.rows - 30);
    n_widget_background(w, "/redhat.logo");
    n_widget_show(w);

    b = NEW_NOBJECT(button);
    n_button_init(b, w, "Close");
    n_button_onclick(b, do_close);
    n_widget_resize(b, 40, 20);
    n_widget_move(b,180,260);
    n_widget_show(b);

    t = NEW_NOBJECT(textfield);
    n_textfield_init(t,w,"Tap all 4 corners");
    n_widget_move(t,45,220);
    n_widget_resize(t,120,20);
    n_widget_show(t);

    t = NEW_NOBJECT(textfield);
    n_textfield_init(t,w,"Then press close");
    n_widget_move(t,45,250);
    n_widget_resize(t,120,20);
    n_widget_show(t);

    while (!closed) {
        n_handle_event();
    }

    n_widget_hide(w);
    n_object_cleanup(w);

#endif

    GrClose();
}
コード例 #13
0
ファイル: fontutil.cpp プロジェクト: CodeSmithyIDE/wxWidgets
static wxNativeFont wxLoadQueryFont(float pointSize,
                                    wxFontFamily family,
                                    wxFontStyle style,
                                    int weight,
                                    bool WXUNUSED(underlined),
                                    const wxString& facename,
                                    const wxString& xregistry,
                                    const wxString& xencoding,
                                    wxString* xFontName)
{
#if wxUSE_NANOX
    int xweight;
    switch (weight)
    {
         case wxFONTWEIGHT_BOLD:
             {
                 xweight = MWLF_WEIGHT_BOLD;
                 break;
             }
        case wxFONTWEIGHT_LIGHT:
             {
                 xweight = MWLF_WEIGHT_LIGHT;
                 break;
             }
         case wxFONTWEIGHT_NORMAL:
             {
                 xweight = MWLF_WEIGHT_NORMAL;
                 break;
             }

     default:
             {
                 xweight = MWLF_WEIGHT_DEFAULT;
                 break;
             }
    }
    GR_SCREEN_INFO screenInfo;
    GrGetScreenInfo(& screenInfo);

    int yPixelsPerCM = screenInfo.ydpcm;

    // A point is 1/72 of an inch.
    // An inch is 2.541 cm.
    // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
    // In fact pointSize is 10 * the normal point size so
    // divide by 10.

    int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ;

    // An alternative: assume that the screen is 72 dpi.
    //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
    //int pixelHeight = (int) ((float)pointSize / 10.0) ;

    GR_LOGFONT logFont;
    logFont.lfHeight = pixelHeight;
    logFont.lfWidth = 0;
    logFont.lfEscapement = 0;
    logFont.lfOrientation = 0;
    logFont.lfWeight = xweight;
    logFont.lfItalic = (style == wxFONTSTYLE_ITALIC ? 0 : 1) ;
    logFont.lfUnderline = 0;
    logFont.lfStrikeOut = 0;
    logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one
    logFont.lfOutPrecision = MWLF_TYPE_DEFAULT;
    logFont.lfClipPrecision = 0; // Not used
    logFont.lfRoman = (family == wxROMAN ? 1 : 0) ;
    logFont.lfSerif = (family == wxSWISS ? 0 : 1) ;
    logFont.lfSansSerif = !logFont.lfSerif ;
    logFont.lfModern = (family == wxMODERN ? 1 : 0) ;
    logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ;
    logFont.lfOblique = 0;
    logFont.lfSmallCaps = 0;
    logFont.lfPitch = 0; // 0 = default
    strcpy(logFont.lfFaceName, facename.c_str());

    XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct));
    fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont);
    GrGetFontInfo(fontInfo->fid, & fontInfo->info);
    return (wxNativeFont) fontInfo;

#else
    wxNativeFontInfo info;
    info.SetFractionalPointSize(pointSize);

    if ( !facename.empty() )
    {
        info.SetFaceName(facename);
        if ( !wxTestFontSpec(info.GetXFontName()) )
        {
            // No such face name, use just the family (we assume this will
            // never fail).
            info.SetFamily(family);
        }
    }
    else
    {
        info.SetFamily(family);
    }

    wxNativeFontInfo infoWithStyle(info);
    infoWithStyle.SetStyle(style);
    if ( wxTestFontSpec(infoWithStyle.GetXFontName()) )
        info = infoWithStyle;

    wxNativeFontInfo infoWithWeight(info);
    infoWithWeight.SetNumericWeight(weight);
    if ( wxTestFontSpec(infoWithWeight.GetXFontName()) )
        info = infoWithWeight;

    // construct the X font spec from our data
    wxString fontSpec;
    fontSpec.Printf("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s",
                    info.GetXFontComponent(wxXLFD_FAMILY),
                    info.GetXFontComponent(wxXLFD_WEIGHT),
                    info.GetXFontComponent(wxXLFD_SLANT),
                    info.GetXFontComponent(wxXLFD_POINTSIZE),
                    xregistry,
                    xencoding);

    if( xFontName )
        *xFontName = fontSpec;

    return wxLoadFont(fontSpec);
#endif
    // wxUSE_NANOX
}
コード例 #14
0
ファイル: fontutil.cpp プロジェクト: beanhome/dev
static wxNativeFont wxLoadQueryFont(int pointSize,
                                    int family,
                                    int style,
                                    int weight,
                                    bool WXUNUSED(underlined),
                                    const wxString& facename,
                                    const wxString& xregistry,
                                    const wxString& xencoding,
                                    wxString* xFontName)
{
    wxString xfamily;
    switch (family)
    {
        case wxDECORATIVE: xfamily = wxT("lucida"); break;
        case wxROMAN:      xfamily = wxT("times");  break;
        case wxMODERN:     xfamily = wxT("courier"); break;
        case wxSWISS:      xfamily = wxT("helvetica"); break;
        case wxTELETYPE:   xfamily = wxT("lucidatypewriter"); break;
        case wxSCRIPT:     xfamily = wxT("utopia"); break;
        default:           xfamily = wxT("*");
    }
#if wxUSE_NANOX
    int xweight;
    switch (weight)
    {
         case wxBOLD:
             {
                 xweight = MWLF_WEIGHT_BOLD;
                 break;
             }
        case wxLIGHT:
             {
                 xweight = MWLF_WEIGHT_LIGHT;
                 break;
             }
         case wxNORMAL:
             {
                 xweight = MWLF_WEIGHT_NORMAL;
                 break;
             }

     default:
             {
                 xweight = MWLF_WEIGHT_DEFAULT;
                 break;
             }
    }
    GR_SCREEN_INFO screenInfo;
    GrGetScreenInfo(& screenInfo);

    int yPixelsPerCM = screenInfo.ydpcm;

    // A point is 1/72 of an inch.
    // An inch is 2.541 cm.
    // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
    // In fact pointSize is 10 * the normal point size so
    // divide by 10.

    int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ;

    // An alternative: assume that the screen is 72 dpi.
    //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
    //int pixelHeight = (int) ((float)pointSize / 10.0) ;

    GR_LOGFONT logFont;
    logFont.lfHeight = pixelHeight;
    logFont.lfWidth = 0;
    logFont.lfEscapement = 0;
    logFont.lfOrientation = 0;
    logFont.lfWeight = xweight;
    logFont.lfItalic = (style == wxNORMAL ? 0 : 1) ;
    logFont.lfUnderline = 0;
    logFont.lfStrikeOut = 0;
    logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one
    logFont.lfOutPrecision = MWLF_TYPE_DEFAULT;
    logFont.lfClipPrecision = 0; // Not used
    logFont.lfRoman = (family == wxROMAN ? 1 : 0) ;
    logFont.lfSerif = (family == wxSWISS ? 0 : 1) ;
    logFont.lfSansSerif = !logFont.lfSerif ;
    logFont.lfModern = (family == wxMODERN ? 1 : 0) ;
    logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ;
    logFont.lfOblique = 0;
    logFont.lfSmallCaps = 0;
    logFont.lfPitch = 0; // 0 = default
    strcpy(logFont.lfFaceName, facename.c_str());

    XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct));
    fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont);
    GrGetFontInfo(fontInfo->fid, & fontInfo->info);
    return (wxNativeFont) fontInfo;

#else
    wxString fontSpec;
    if (!facename.empty())
    {
        fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
                        facename.c_str());

        if ( wxTestFontSpec(fontSpec) )
        {
            xfamily = facename;
        }
        //else: no such family, use default one instead
    }

    wxString xstyle;
    switch (style)
    {
        case wxSLANT:
            fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
                    xfamily.c_str());
            if ( wxTestFontSpec(fontSpec) )
            {
                xstyle = wxT("o");
                break;
            }
            // fall through - try wxITALIC now

        case wxITALIC:
            fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
                    xfamily.c_str());
            if ( wxTestFontSpec(fontSpec) )
            {
                xstyle = wxT("i");
            }
            else if ( style == wxITALIC ) // and not wxSLANT
            {
                // try wxSLANT
                fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
                        xfamily.c_str());
                if ( wxTestFontSpec(fontSpec) )
                {
                    xstyle = wxT("o");
                }
                else
                {
                    // no italic, no slant - leave default
                    xstyle = wxT("*");
                }
            }
            break;

        default:
            wxFAIL_MSG(wxT("unknown font style"));
            // fall back to normal

        case wxNORMAL:
            xstyle = wxT("r");
            break;
    }

    wxString xweight;
    switch (weight)
    {
         case wxBOLD:
             {
                  fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("bold");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("heavy");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("extrabold");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("demibold");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("black");
                      break;
                  }
                  fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("ultrablack");
                      break;
                  }
              }
              break;
        case wxLIGHT:
             {
                  fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("light");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("thin");
                       break;
                  }
             }
             break;
         case wxNORMAL:
             {
                  fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("medium");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                       xweight = wxT("normal");
                       break;
                  }
                  fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
                         xfamily.c_str());
                  if ( wxTestFontSpec(fontSpec) )
                  {
                      xweight = wxT("regular");
                      break;
                  }
                  xweight = wxT("*");
              }
              break;
        default:           xweight = wxT("*"); break;
    }

    // if pointSize is -1, don't specify any
    wxString sizeSpec;
    if ( pointSize == -1 )
    {
        sizeSpec = wxT('*');
    }
    else
    {
        sizeSpec.Printf(wxT("%d"), pointSize);
    }

    // construct the X font spec from our data
    fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
                    xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
                    sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str());

    if( xFontName )
        *xFontName = fontSpec;

    return wxLoadFont(fontSpec);
#endif
    // wxUSE_NANOX
}
コード例 #15
0
ファイル: FontCursor.c プロジェクト: BadrElh/microwindows
/* Assign an arbitrary char to the cursor */
Cursor
XCreateGlyphCursor(Display * display, Font source_font, Font mask_font,
		   unsigned int source_char, unsigned int mask_char,
		   XColor XCONST * foreground, XColor XCONST * background)
{
	Cursor		ret;
	int		tw[2], th[2], tb[2];
	unsigned char	ch[2];
	GR_GC_ID	gc;
	GR_WINDOW_ID	cursor;
	GR_COLOR	fc, bc;
	GR_RECT		cbb, mbb;
	GR_FONT_INFO	srcinfo, maskinfo;

	gc = GrNewGC();
	/*GrSetGCUseBackground(gc, GR_FALSE);*/ /* assume NewGC defaults TRUE*/
	GrSetGCForeground(gc, GR_RGB(255, 255, 255));
	GrSetGCBackground(gc, GR_RGB(  0,   0,   0));

	/* Draw both the fonts into their appropriate pixmap, and create the cursor */
	GrGetFontInfo((GR_FONT_ID) source_font, &srcinfo);
	GrGetFontInfo((GR_FONT_ID) mask_font, &maskinfo);

	ch[0] = srcinfo.firstchar + source_char;
	ch[1] = maskinfo.firstchar + mask_char;

	/* Use the mask as the determining size */
	GrSetGCFont(gc, (GR_FONT_ID) mask_font);

	GrGetGCTextSize(gc, &ch[0], 1, GR_TFTOP, &tw[0], &th[0], &tb[0]);
	GrGetGCTextSize(gc, &ch[1], 1, GR_TFTOP, &tw[1], &th[1], &tb[1]);

	cursor = GrNewPixmap(tw[1] * 2, th[1], 0);

	/* Draw the mask first, to avoid having to switch fonts in the GC */
	GrText(cursor, gc, tw[1], 0, &ch[1], 1, GR_TFTOP|GR_TFASCII);

	/* Offset the first char by 1 1 */
	GrSetGCFont(gc, (GR_FONT_ID) source_font);
	GrText(cursor, gc, 1, 1, &ch[0], 1, GR_TFTOP|GR_TFASCII);

	/* Calculate the bounding box */
	cbb.x = 0;
	cbb.y = 0;
	cbb.width = tw[0];
	cbb.height = th[0];

	mbb.x = tw[1];
	mbb.y = 0;
	mbb.width = tw[1];
	mbb.height = th[1];

	fc = GR_RGB(foreground->red >> 8, foreground->green >> 8,
			foreground->blue >> 8);
	bc = GR_RGB(background->red >> 8, background->green >> 8,
			background->blue >> 8);
	/* cursor hotspot is (leftbearing, ascent)*/
	ret = _nxCreateCursor(cursor, &cbb, cursor, &mbb, 0, tb[1],
			fc, bc);

	GrDestroyWindow(cursor);
	GrDestroyGC(gc);
	return ret;
}
コード例 #16
0
/* Set the contents of the state structure to default parameters. */
static void setup_default_state(nbstate *state)
{
	int i;
	GR_FONT_ID fid;
	GR_FONT_INFO fi;

	state->state = STATE_TITLESCREEN;
	state->gamedir = DEFAULT_GAME_DIR;
	state->gamefile = DEFAULT_GAME_FILE;
	state->titlebackground = NULL;
	state->titlebackgroundtiled = DEFAULT_BACKGROUND_TILED;
	state->titlesplash = NULL;
	state->gamewonsplash = NULL;
	state->gamelostsplash = NULL;
	state->spritelist = NULL;
	state->background = NULL;
	state->backgroundtiled = 1;
	state->normalpoints = DEFAULT_NORMALPOINTS;
	state->smallbonuspoints = DEFAULT_SMALLBONUSPOINTS;
	state->mediumbonuspoints = DEFAULT_MEDIUMBONUSPOINTS;
	state->largebonuspoints = DEFAULT_LARGEBONUSPOINTS;
	state->hugebonuspoints = DEFAULT_HUGEBONUSPOINTS;
	state->poweruppoints = DEFAULT_POWERUPPOINTS;
	state->powerdownpoints = DEFAULT_POWERDOWNPOINTS;
	state->startballs = DEFAULT_STARTBALLS;
	state->newlevelballs = DEFAULT_NEWLEVELBALLS;
	state->brickwidth = DEFAULT_BRICK_WIDTH;
	state->brickheight = DEFAULT_BRICK_HEIGHT;
	state->bricks = NULL;
	state->brickalpha = 0;
	state->width = DEFAULT_WIDTH;
	state->height = DEFAULT_HEIGHT;
	state->batheight = DEFAULT_BAT_HEIGHT;
	state->batwidths[NORMALBAT] = DEFAULT_NORMALBAT_WIDTH;
	state->batwidths[SMALLBAT] = DEFAULT_SMALLBAT_WIDTH;
	state->batwidths[LARGEBAT] = DEFAULT_LARGEBAT_WIDTH;
	for(i = 0; i < NUMBATS; i++) state->bats[i] = NULL;
	state->bat = NORMALBAT;
	state->batx = 0;
	state->batv = DEFAULT_BAT_VELOCITY;
	state->powerv = DEFAULT_POWER_VELOCITY;
	state->animateperiod = DEFAULT_ANIMATE_PERIOD;
	for(i = 0; i < NUMPOWERS; i++) state->powersprites[i] = NULL;
	state->splash = NULL;
	state->poweruptime = DEFAULT_POWERUP_TIME;
	state->powerdowntime = DEFAULT_POWERDOWN_TIME;
	for(i = 0; i < NUMCHEATS; i++) state->cheats[i] = NULL;
	memset(state->cheatstate, 0, MAXCHEATLEN + 1);
	state->flags.sf = 0;
	state->flags.nb = 0;
	state->flags.npd = 0;
	state->flags.nputo = 0;
	state->flags.paused = 0;
	state->flags.left = 0;
	state->flags.right = 0;
	state->levels = NULL;
	state->level = 0;
	state->numlevels = 0;
	state->wid = 0;
	state->winx = 0;
	state->canvas = 0;
	state->canvaswidth = 0;
	state->canvasheight = 0;
	state->grid = NULL;
	state->numbricks = 0;
	state->powers = NULL;
	state->scores.s = 0;
	state->scores.hi = 0;
	state->scores.fhi = 0;
	state->scores.p = 0;
	state->gc = GrNewGC();
	fid = GrCreateFont(SCORE_FONT, 0, NULL);
	GrGetFontInfo(fid, &fi);
	state->scores.h = (2 * SCORE_BORDER) + fi.height;
	GrSetGCFont(state->gc, fid);
	state->ball.x = 0;
	state->ball.y = 0;
	state->ball.d = 0;
	state->ball.v = DEFAULT_NORMAL_BALL_VELOCITY;
	state->ball.lx = 0;
	state->ball.ly = 0;
	state->ball.parked = 1;
	state->ball.s = NULL;
	state->ball.sv = DEFAULT_SLOW_BALL_VELOCITY;
	state->ball.nv = DEFAULT_NORMAL_BALL_VELOCITY;
	state->ball.fv = DEFAULT_FAST_BALL_VELOCITY;
	state->numballs = 0;
	gettimeofday(&state->lastanim, NULL);
	state->powertimes.widebat = 0;
	state->powertimes.slowmotion = 0;
	state->powertimes.stickybat = 0;
	state->powertimes.powerball = 0;
	state->powertimes.narrowbat = 0;
	state->powertimes.fastmotion = 0;
	state->faderate = DEFAULT_FADERATE;
	state->fadelevel = 0;
	state->nextstate = STATE_TITLESCREEN;
}
コード例 #17
0
ファイル: landmine.c プロジェクト: thegeek82000/lepton
int
main(int argc,char **argv)
{
    GR_COORD	x;
    GR_COORD	y;
    GR_SIZE		width;
    GR_SIZE		height;
    GR_COORD	rightx;		/* x coordinate for right half stuff */
    GR_BOOL		setsize;	/* TRUE if size of board is set */
    GR_BOOL		setmines;	/* TRUE if number of mines is set */
    GR_SIZE		newsize = 10;	/* desired size of board */
    GR_COUNT	newmines = 25;	/* desired number of mines */
    GR_WM_PROPERTIES props;

    setmines = GR_FALSE;
    setsize = GR_FALSE;

    argc--;
    argv++;
    while ((argc > 0) && (**argv == '-')) {
        switch (argv[0][1]) {
        case 'm':
            if (argc <= 0) {
                fprintf(stderr, "Missing mine count\n");
                exit(1);
            }
            argc--;
            argv++;
            newmines = atoi(*argv);
            setmines = GR_TRUE;
            break;

        case 's':
            if (argc <= 0) {
                fprintf(stderr, "Missing size\n");
                exit(1);
            }
            argc--;
            argv++;
            newsize = atoi(*argv);
            setsize = GR_TRUE;
            break;

        default:
            fprintf(stderr, "Unknown option \"-%c\"\n",
                    argv[0][1]);
            exit(1);
        }
        argc--;
        argv++;
    }
    if (argc > 0)
        savefile = *argv;

    srand(time(0));

    readgame(savefile);

    if (setsize) {
        if ((newsize < MINSIZE) || (newsize > MAXSIZE)) {
            fprintf(stderr, "Illegal board size\n");
            exit(1);
        }
        if (newsize != size) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change size while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            size = newsize;
            if (!playing)
                mines = (size * size * MINEPERCENT) / 100;
        }
    }

    if (setmines) {
        if ((newmines <= 0) || ((newmines > (size * size) / 2))) {
            fprintf(stderr, "Illegal number of mines\n");
            exit(1);
        }
        if (newmines != mines) {
            if (steps && playing) {
                fprintf(stderr,
                        "Cannot change mines while game is in progress\n");
                exit(1);
            }
            playing = GR_FALSE;
            mines = newmines;
        }
    }

    findindex();

    /*
     * Parameters of the game have been verified.
     * Now open the graphics and play the game.
     */

    if (GrOpen() < 0) {
        fprintf(stderr, "Cannot open graphics\n");
        exit(1);
    }

    GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */

    GrGetScreenInfo(&si);
    GrGetFontInfo(0, &fi);
    charheight = fi.height;

    /*
     * Create the main window which will contain all the others.
     */
#if 0
    COLS = si.cols - 40;
#else
    COLS = si.cols;
#endif
    ROWS = si.rows - 80;
    mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS,
                          0, BLACK, WHITE);

    /* set title */
    props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS;
    props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION;
    props.title = "Land Mine";
    GrSetWMProperties(mainwid, &props);

    /*
     * Create the board window which lies at the left side.
     * Make the board square, and as large as possible while still
     * leaving room to the right side for statistics and buttons.
     */
    width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2;
    height = (((long) width) * si.ydpcm) / si.xdpcm;
    if (height > ROWS /* - y * 2*/) {
        height = ROWS - BOARDBORDER * 2;
        width = (((long) height) * si.xdpcm) / si.ydpcm;
    }
    xp = width / size;
    yp = height / size;

    width = xp * size - 1;
    height = yp * size - 1;
    x = BOARDBORDER;
    y = (ROWS - height) / 2;

    rightx = x + width + (si.xdpcm * RIGHTGAP / 10);
    boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER,
                           BLUE, WHITE);
    /*
     * Create the buttons.
     */
    x = rightx;
    y = (si.ydpcm * BOARDGAP / 10);
    quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, RED, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                          1, GREEN, WHITE);

    y += (si.ydpcm * BUTTONGAP / 10);
    newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT,
                             1, GREEN, WHITE);

    /*
     * Create the statistics window.
     */
    x = rightx;
    y += (si.ydpcm * STATUSGAP / 10);
    width = COLS - x;
    height = ROWS - y;
    statwid = GrNewWindow(mainwid, x, y, width, height, 0,
                          0, 0);
    statwidth = width;
    statheight = height;

    /*
     * Create the GC for drawing the board.
     */
    boardgc = GrNewGC();
    cleargc = GrNewGC();
    delaygc = GrNewGC();
    redgc = GrNewGC();
    greengc = GrNewGC();
    statgc = GrNewGC();
    blackgc = GrNewGC();
    buttongc = GrNewGC();
    xorgc = GrNewGC();
    GrSetGCBackground(boardgc, BLUE);
    GrSetGCForeground(cleargc, BLUE);
    GrSetGCForeground(redgc, RED);
    GrSetGCForeground(greengc, GREEN);
    GrSetGCForeground(statgc, GRAY);
    GrSetGCForeground(delaygc, BLACK);
    GrSetGCForeground(blackgc, BLACK);
    GrSetGCMode(delaygc, GR_MODE_XOR);
    GrSetGCMode(xorgc, GR_MODE_XOR);
    GrSetGCUseBackground(boardgc, GR_FALSE);
    GrSetGCUseBackground(buttongc, GR_FALSE);

    GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ);

    GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN);

    GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE);

    GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE |
                   GR_EVENT_MASK_BUTTON_DOWN);

    setcursor();

    GrMapWindow(mainwid);
    GrMapWindow(boardwid);
    GrMapWindow(statwid);
    GrMapWindow(quitwid);
    GrMapWindow(savewid);
    GrMapWindow(newgamewid);

    if (!playing)
        newgame();

    while (GR_TRUE) {
        GR_EVENT event;

        GrGetNextEvent(&event);
        handleevent(&event);
    }
}
コード例 #18
0
ファイル: pcfdemo.c プロジェクト: BadrElh/microwindows
int
main(int argc, char **argv)
{
	GR_WINDOW_ID main_wid;
	GR_TIMEOUT timeout;
	int width, height;

	if (argc != 2)
		return (-1);

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFontEx(argv[1], 12, 12, 0);
	if (!font)
		printf("Unable to load %s\n", argv[1]);

	GrGetFontInfo(font, &finfo);

	printf("font_id = %d\n", font);
	printf("First char = %d, last char = %d\n", finfo.firstchar, finfo.lastchar);
	printf("Max width = %d, max height = %d\n", finfo.maxwidth, finfo.height);
	printf("baseline = ascent = %d, descent = %d\n", finfo.baseline, finfo.descent);
	printf("max ascent = %d, max descent = %d\n", finfo.maxascent, finfo.maxdescent);
	printf("linespacing = %d, fixed = %s\n", finfo.linespacing, finfo.fixed? "yes": "no");

//	finfo.firstchar = 0;	/* force display of undefined chars, test with jiskan24.pcf.gz*/

	/* determine window metrics*/
	width = (finfo.maxwidth + spacer) * line_width + 2 * border - spacer;
	if (width > 640) {
		line_width /= 2;
		lines *= 2;
		width = (finfo.maxwidth + 2) * line_width + 2 * border - spacer;
    }
	height = lines * (finfo.height + spacer) + 2 * border - spacer;
	chars_to_show = lines * line_width;

	/* create the main application window*/
	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "pcfdemo",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	if (finfo.lastchar >= chars_to_show)
		timeout = 8 * 1000;
    else timeout = 0;

	while (1) {
		GR_EVENT event;
		GrGetNextEventTimeout(&event, timeout);

		if (event.type == GR_EVENT_TYPE_TIMEOUT) {
			first_char += chars_to_show;
            draw_string(main_wid);
		}
		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			draw_string(main_wid);
		if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	   }
	}
}