Mercurial > otakunoraifu
diff font/font_peer_x11.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 5f548e5957a8 |
children | 4416cfac86ae |
line wrap: on
line diff
--- a/font/font_peer_x11.cc +++ b/font/font_peer_x11.cc @@ -40,12 +40,12 @@ #include <X11/Xutil.h> #include <X11/extensions/XShm.h> #include <stdio.h> -#include<iostream> +#include <iostream> -#include<vector> -#include<map> -//#include<iostream> -#include<sstream> +#include <vector> +#include <map> + +#include <sstream> #include <string> #include <stdexcept> @@ -86,7 +86,9 @@ FontInfo::FontInfo(Display* display, con /* フォントの大きさ関係の情報を消去 */ int i; char* fontname = new char[strlen(fontname_orig)+50]; - int minus_count = 0; bool is_skip = false; int fc = 0; + int minus_count = 0; + bool is_skip = false; + int fc = 0; for (i=0; fontname_orig[i]!=0; i++) { if (fontname_orig[i] == '-') { minus_count++; @@ -107,7 +109,8 @@ FontInfo::FontInfo(Display* display, con for (i=0; i<count; i++) { char* curfont = fontnamelist[i]; /* fontname から pixel size 情報を得る */ - int j; int minus_count = 0; + int j; + int minus_count = 0; for (j=0; curfont[j] != 0; j++) { if (curfont[j] == '-') minus_count++; if (minus_count == 7) { @@ -142,7 +145,9 @@ string FontInfo::Search(int pixsize) { string basefont_s = fontlist[0]; const char* basefont = basefont_s.c_str(); char* retfont = new char[strlen(basefont)+50]; - int minus_count = 0; int rc = 0; bool is_skip = false; + int minus_count = 0; + int rc = 0; + bool is_skip = false; for (i=0; basefont[i] != 0; i++) { if (basefont[i] == '-') { minus_count++; @@ -195,7 +200,7 @@ string FontSetInfo::Search(int pixsize) if (it != fontlist.begin()) s << ","; s << (*it)->Search(pixsize); } - s<<ends; + s << ends; return string(s.str()); } @@ -203,21 +208,21 @@ string FontSetInfo::Search(int pixsize) ** ** FontPeerX11 */ -Display* PeerX11::display = 0; +Display* PeerX11::display = NULL; void PeerX11::InitDisplay(Display* _d) { /* d = ((GdkWindowPrivate*)(top_window.gdkobj()))->xdisplay; */ display = _d; } void PeerX11::OpenDisplay(void) { - if (display) return; + if (display != NULL) return; const char* display_name = getenv("DISPLAY"); - if (display_name == 0) display_name = ":0"; + if (display_name == NULL) display_name = ":0"; display = XOpenDisplay(display_name); - if (display == 0) { + if (display == NULL) { string err = string("XKFont::PeerX11:OpenDisplay() : Cannot open X display ") + display_name; throw std::invalid_argument(err); } @@ -254,15 +259,19 @@ PeerX11::PeerX11(const char* fontname, i int tablesize = mask+1; colortable = new int[tablesize]; - int i; for (i=0; i< tablesize; i++) { + int i; + for (i=0; i< tablesize; i++) { colortable[i] = i*255/tablesize; } -XSupportsLocale(); + + XSupportsLocale(); //FIXME: er... yes? /* font 読み込み */ FontSetInfo fsinfo(display,fontname); string fontset_name = fsinfo.Search(fontsize); - char** missing_cl; int missing_cc; char* def_s; + char** missing_cl; + int missing_cc; + char* def_s; printf("fontset %s\n",fontset_name.c_str()); fontset = XCreateFontSet(display, fontset_name.c_str(), &missing_cl, &missing_cc, &def_s); @@ -298,7 +307,8 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC } /* 描画用の pixmap を作成 */ - XGCValues gc_values; unsigned int gc_values_mask; + XGCValues gc_values; + unsigned int gc_values_mask; gc_values.function = GXcopy; gc_values.fill_style = FillSolid; gc_values.arc_mode = ArcPieSlice; @@ -318,11 +328,11 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC x_shm_info.shmid = -1; x_shm_info.shmaddr = (char*)-1; image = XShmCreateImage(display, visual, DefaultDepth(display, scr), ZPixmap, NULL, &x_shm_info, width, height); - if (image) { + if (image != NULL) { x_shm_info.shmid = shmget(IPC_PRIVATE, image->bytes_per_line*image->height, IPC_CREAT | 0600); if (x_shm_info.shmid == -1) { XDestroyImage(image); - image = 0; + image = NULL; goto no_shm; } x_shm_info.readOnly = False; @@ -340,20 +350,21 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC use_shm = true; } } -no_shm: +no_shm: //TODO: Understand why he did it, and supress it if needed if (image == 0) { use_shm = false; image = XCreateImage(display, visual, DefaultDepth(display, scr), ZPixmap, 0, 0, width, height, 32, 0); image->data = (char*)malloc(image->bytes_per_line * image->height); - if (image->data == 0) { + if (image->data == NULL) { XDestroyImage(image); - image = 0; + image = NULL; throw bad_alloc(); } } -Glyph g; -GlyphCreate(0xa1a2,&g); -GlyphCreate(0xa4a3,&g); + + Glyph g; + GlyphCreate(0xa1a2, &g); //FIXME: Two calls? Huh? + GlyphCreate(0xa4a3, &g); } PeerX11::~PeerX11() { @@ -397,7 +408,7 @@ bool PeerX11::GlyphCreate(unsigned int c unsigned char* dest = glyph->bitmap.buffer; int bpp = image->bytes_per_line/width; int bpl = image->bytes_per_line; - for (i=0; i<logic.height; i++) { + for (i=0; i < logic.height; i++) { unsigned char* m = mem; int j; for (j=0; j<cwidth; j++) { *dest = colortable[((read_little_endian_int((char*)m))>>shift) & mask];