HFONT WPDevContext::setFont(LPCSTR face, int ptsize, BOOL italic, int bold) { int mmOld = mapMode(MM_TWIPS); LOGFONT font; memset(&font, 0, sizeof(font)); lstrcpy((char*)font.lfFaceName, face); font.lfHeight = -ptsize * 20; font.lfWeight = bold; font.lfItalic = italic; HFONT hOld = (HFONT)select(SELFONT, CreateFontIndirect(&font), TRUE); mapMode(mmOld); return hOld; }
////////////////// // Create memory DC from bitmap // WPMemDC::WPMemDC(WPDevContext *dc, WPBitmap *bm) { hdc = CreateCompatibleDC(GetHDC(dc)); assert(hdc); if (bm) setBitmap(bm); if (dc) mapMode(dc->mapMode()); }
/* Constructor function open(options: Object = null): File NOTE: options can be an options hash or as mode string */ static EjsObj *openFile(Ejs *ejs, EjsFile *fp, int argc, EjsObj **argv) { EjsObj *options; cchar *mode; int perms, omode; if (argc < 0 || argc > 1) { ejsThrowArgError(ejs, "Bad args"); return 0; } options = argv[0]; if (argc == 0 || !ejsIsDefined(ejs, options)) { omode = O_RDONLY | O_BINARY; perms = EJS_FILE_PERMS; fp->mode = EJS_FILE_READ; mode = "r"; } else { if (ejsIs(ejs, options, String)) { mode = ejsToMulti(ejs, options); perms = EJS_FILE_PERMS; } else { perms = ejsGetNumOption(ejs, options, "permissions", EJS_FILE_PERMS, 1); mode = getStrOption(ejs, options, "mode", "r", 1); if (ejs->exception) { return 0; } } omode = mapMode(mode); if (!(omode & O_WRONLY)) { fp->mode |= EJS_FILE_READ; } if (omode & (O_WRONLY | O_RDWR)) { fp->mode |= EJS_FILE_WRITE; } } fp->modeString = sclone(mode); fp->perms = perms; if (fp->file) { mprCloseFile(fp->file); } fp->file = mprOpenFile(fp->path, omode, perms); if (fp->file == 0) { ejsThrowIOError(ejs, "Cannot open %s", fp->path); return 0; } if (options) { ejsSetPathAttributes(ejs, fp->path, options); } #if ME_CC_MMU && FUTURE mprGetPathInfo(&fp->info); fp->mapped = mapFile(fp, fp->info.size, MPR_MAP_READ | MPR_MAP_WRITE); #endif fp->mode |= EJS_FILE_OPEN; return (EjsObj*) fp; }
////////////////// // Create memory DC compatible w/existing DC. // Rectangle says which window in primary DC to map; // "mono" flags creates monochrome bitmap. // WPMemDC::WPMemDC(WPDevContext *dc, WPRect& winRect, BOOL mono) { hdc = CreateCompatibleDC(GetHDC(dc)); assert(hdc); // Get bitmap dimensions: convert window rect to device coords. WPPoint p(winRect.width(), winRect.height()); if (dc) { dc->LP2DP(&p, 1); mapMode(dc->mapMode()); } HBITMAP h = CreateCompatibleBitmap((dc && !mono) ? (*dc)() : hdc, p.x, p.y); assert(h); select(SELBITMAP, h, TRUE); windowOrg(winRect.origin()); // window origin = top left corner of rect }