int _PGFT_GetMetrics(FreeTypeInstance *ft, PgFontObject *fontobj, PGFT_char character, const FontRenderMode *mode, FT_UInt *gindex, long *minx, long *maxx, long *miny, long *maxy, double *advance_x, double *advance_y) { FontText *ftext = &(PGFT_INTERNALS(fontobj)->active_text); FontGlyph *glyph = 0; TextContext context; FT_Face font; /* load our sized font */ font = _PGFT_GetFontSized(ft, fontobj, mode->pt_size); if (!font) { return -1; } /* cleanup the cache */ _PGFT_Cache_Cleanup(&ftext->glyph_cache); fill_context(&context, ft, fontobj, mode, font); glyph = _PGFT_Cache_FindGlyph(character, mode, &PGFT_INTERNALS(fontobj)->active_text.glyph_cache, &context); if (!glyph) { return -1; } *gindex = glyph->glyph_index; *minx = (long)glyph->image->left; *maxx = (long)(glyph->image->left + glyph->image->bitmap.width); *maxy = (long)glyph->image->top; *miny = (long)(glyph->image->top - glyph->image->bitmap.rows); *advance_x = (double)(glyph->h_metrics.advance_rotated.x / 64.0); *advance_y = (double)(glyph->h_metrics.advance_rotated.y / 64.0); return 0; }
int do_scroll_proc(HWND hwnd,int lines,int dir,int update_pos) { int delta; if(open_file(&gfh)){ delta=seek_line_relative(gfh,lines,dir); if(dir>0) current_line+=delta; else if(dir<0) current_line-=delta; fill_context(hwnd,IDC_CONTEXT,gfh); if(update_pos) set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh); return close_file(&gfh); } else{ WCHAR str[MAX_PATH*2]={0}; _snwprintf(str,sizeof(str)/sizeof(WCHAR),L"Cant open %s",fname); str[sizeof(str)/sizeof(WCHAR)-1]=0; MessageBoxW(hwnd,str,L"error",MB_OK); return FALSE; } }
/* * Due to lack of time this is just fwparam_ppc_boot_info which * adds the target used for boot to the list. It does not add * all possible targets (IBM please add). */ int fwparam_ppc_get_targets(struct list_head *list) { char filename[FILENAMESZ]; struct boot_context *context; int error; char *devtree; /* * For powerpc, our operations are fundamentally to locate * either the one boot target (the singleton disk), or to find * the nics that support iscsi boot. The only nics in IBM * systems that can support iscsi are the ones that provide * the appropriate FCODE with a load method. */ memset(filename, 0, FILENAMESZ); snprintf(filename, FILENAMESZ, "%s%s", DT_TOP, BOOTPATH); if (debug) fprintf(stderr, "%s: file:%s; debug:%d\n", __func__, filename, debug); devtree = find_devtree(filename); if (!devtree) return EINVAL; /* * Always search the device-tree to find the capable nic devices. */ error = loop_devs(devtree); if (error) goto free_devtree; if (find_file(filename) < 1) error = ENODEV; else { if (debug) printf("%s:\n%s\n\n", filename, bootpath_val); /* * We find *almost* everything we need in the * bootpath, save the mac-address. */ if (!strstr(bootpath_val, "iscsi")) { error = EINVAL; goto free_devtree; } ofwdevs[0] = calloc(1, sizeof(struct ofw_dev)); if (!ofwdevs[0]) { error = ENOMEM; goto free_devtree; } error = parse_params(bootpath_val, ofwdevs[0]); if (!error) error = locate_mac(devtree, ofwdevs[0]); if (!error) { context = calloc(1, sizeof(*context)); if (!context) error = ENOMEM; else { fill_context(context, ofwdevs[0]); list_add_tail(&context->list, list); } } free(ofwdevs[0]); } free_devtree: free(devtree); return error; }
FontText * _PGFT_LoadFontText(FreeTypeInstance *ft, PgFontObject *fontobj, const FontRenderMode *mode, PGFT_String *text) { Py_ssize_t string_length = PGFT_String_GET_LENGTH(text); PGFT_char * buffer = PGFT_String_GET_DATA(text); PGFT_char * buffer_end; PGFT_char * ch; FontText *ftext = &(PGFT_INTERNALS(fontobj)->active_text); FontGlyph *glyph = 0; FontGlyph **glyph_array = 0; FontMetrics *metrics; FT_BitmapGlyph image; TextContext context; FT_Face font; FT_Size_Metrics *sz_metrics; FT_Vector pen = {0, 0}; /* untransformed origin */ FT_Vector pen1 = {0, 0}; FT_Vector pen2; FT_Vector *next_pos; int vertical = mode->render_flags & FT_RFLAG_VERTICAL; int use_kerning = mode->render_flags & FT_RFLAG_KERNING; int pad = mode->render_flags & FT_RFLAG_PAD; FT_UInt prev_glyph_index = 0; /* All these are 16.16 precision */ FT_Angle rotation_angle = mode->rotation_angle; /* All these are 26.6 precision */ FT_Vector kerning; FT_Pos min_x = FX6_MAX; FT_Pos max_x = FX6_MIN; FT_Pos min_y = FX6_MAX; FT_Pos max_y = FX6_MIN; FT_Pos glyph_width; FT_Pos glyph_height; FT_Pos top = FX6_MIN; FT_Fixed y_scale; FT_Error error = 0; /* load our sized font */ font = _PGFT_GetFontSized(ft, fontobj, mode->pt_size); if (!font) { PyErr_SetString(PyExc_SDLError, _PGFT_GetError(ft)); return 0; } sz_metrics = &font->size->metrics; y_scale = sz_metrics->y_scale; /* cleanup the cache */ _PGFT_Cache_Cleanup(&ftext->glyph_cache); /* create the text struct */ if (string_length > ftext->buffer_size) { _PGFT_free(ftext->glyphs); ftext->glyphs = (FontGlyph **) _PGFT_malloc((size_t)string_length * sizeof(FontGlyph *)); if (!ftext->glyphs) { PyErr_NoMemory(); return 0; } _PGFT_free(ftext->posns); ftext->posns = (FT_Vector *) _PGFT_malloc((size_t)string_length * sizeof(FT_Vector)); if (!ftext->posns) { PyErr_NoMemory(); return 0; } ftext->buffer_size = string_length; } ftext->length = string_length; ftext->ascender = sz_metrics->ascender; ftext->underline_pos = -FT_MulFix(font->underline_position, y_scale); ftext->underline_size = FT_MulFix(font->underline_thickness, y_scale); if (mode->style & FT_STYLE_STRONG) { FT_Fixed bold_str = mode->strength * sz_metrics->x_ppem; ftext->underline_size = FT_MulFix(ftext->underline_size, FX16_ONE + bold_str / 4); } /* fill it with the glyphs */ fill_context(&context, ft, fontobj, mode, font); glyph_array = ftext->glyphs; next_pos = ftext->posns; for (ch = buffer, buffer_end = ch + string_length; ch < buffer_end; ++ch) { pen2.x = pen1.x; pen2.y = pen1.y; pen1.x = pen.x; pen1.y = pen.y; /* * Load the corresponding glyph from the cache */ glyph = _PGFT_Cache_FindGlyph(*((FT_UInt32 *)ch), mode, &ftext->glyph_cache, &context); if (!glyph) { --ftext->length; continue; } image = glyph->image; glyph_width = glyph->width; glyph_height = glyph->height; /* * Do size calculations for all the glyphs in the text */ if (use_kerning && prev_glyph_index) { error = FT_Get_Kerning(font, prev_glyph_index, glyph->glyph_index, FT_KERNING_UNFITTED, &kerning); if (error) { _PGFT_SetError(ft, "Loading glyphs", error); PyErr_SetString(PyExc_SDLError, _PGFT_GetError(ft)); return 0; } if (rotation_angle != 0) { FT_Vector_Rotate(&kerning, rotation_angle); } pen.x += FX6_ROUND(kerning.x); pen.y += FX6_ROUND(kerning.y); if (FT_Vector_Length(&pen2) > FT_Vector_Length(&pen)) { pen.x = pen2.x; pen.y = pen2.y; } } prev_glyph_index = glyph->glyph_index; metrics = vertical ? &glyph->v_metrics : &glyph->h_metrics; if (metrics->bearing_rotated.y > top) { top = metrics->bearing_rotated.y; } if (pen.x + metrics->bearing_rotated.x < min_x) { min_x = pen.x + metrics->bearing_rotated.x; } if (pen.x + metrics->bearing_rotated.x + glyph_width > max_x) { max_x = pen.x + metrics->bearing_rotated.x + glyph_width; } next_pos->x = pen.x + metrics->bearing_rotated.x; pen.x += metrics->advance_rotated.x; if (vertical) { if (pen.y + metrics->bearing_rotated.y < min_y) { min_y = pen.y + metrics->bearing_rotated.y; } if (pen.y + metrics->bearing_rotated.y + glyph_height > max_y) { max_y = pen.y + metrics->bearing_rotated.y + glyph_height; } next_pos->y = pen.y + metrics->bearing_rotated.y; pen.y += metrics->advance_rotated.y; } else { if (pen.y - metrics->bearing_rotated.y < min_y) { min_y = pen.y - metrics->bearing_rotated.y; } if (pen.y - metrics->bearing_rotated.y + glyph_height > max_y) { max_y = pen.y - metrics->bearing_rotated.y + glyph_height; } next_pos->y = pen.y - metrics->bearing_rotated.y; pen.y -= metrics->advance_rotated.y; } *glyph_array++ = glyph; ++next_pos; } if (ftext->length == 0) { min_x = 0; max_x = 0; if (vertical) { ftext->min_y = 0; max_y = sz_metrics->height; } else { FT_Size_Metrics *sz_metrics = &font->size->metrics; min_y = -sz_metrics->ascender; max_y = -sz_metrics->descender; } } if (pad) { FT_Size_Metrics *sz_metrics = &font->size->metrics; if (pen.x > max_x) { max_x = pen.x; } else if (pen.x < min_x) { min_x = pen.x; } if (pen.y > max_y) { max_y = pen.y; } else if (pen.y < min_y) { min_y = pen.y; } if (vertical) { FT_Fixed right = sz_metrics->max_advance / 2; if (max_x < right) { max_x = right; } if (min_x > -right) { min_x = -right; } if (min_y > 0) { min_y = 0; } else if (max_y < pen.y) { max_y = pen.y; } } else { FT_Fixed ascender = sz_metrics->ascender; FT_Fixed descender = sz_metrics->descender; if (min_x > 0) { min_x = 0; } if (max_x < pen.x) { max_x = pen.x; } if (min_y > -ascender) { min_y = -ascender; } if (max_y <= -descender) { max_y = -descender + /* baseline */ FX6_ONE; } } } ftext->left = FX6_TRUNC(FX6_FLOOR(min_x)); ftext->top = FX6_TRUNC(FX6_CEIL(top)); ftext->min_x = min_x; ftext->max_x = max_x; ftext->min_y = min_y; ftext->max_y = max_y; ftext->advance.x = pen.x; ftext->advance.y = pen.y; return ftext; }
LRESULT CALLBACK view_context_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { static HWND grippy=0; int lines,dir,do_scroll=FALSE,update_scroll_pos=TRUE; static int divider_drag=FALSE,org_row_width=90,row_width=90,last_pos=0; #ifdef _DEBUG if(FALSE) // if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE) // if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_DRAWITEM // &&msg!=WM_CTLCOLORBTN&&msg!=WM_CTLCOLOREDIT&&msg!=WM_CTLCOLORSCROLLBAR) if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE) { static DWORD tick=0; if((GetTickCount()-tick)>500) printf("--\n"); printf("v"); print_msg(msg,lparam,wparam); tick=GetTickCount(); } #endif switch(msg) { case WM_INITDIALOG: grippy=create_grippy(hwnd); init_context_win_anchor(hwnd); get_ini_value("CONTEXT_WINDOW","row_width",&row_width); set_context_divider(hwnd,row_width); restore_context_rel_pos(hwnd); SendDlgItemMessage(hwnd,IDC_CONTEXT_SCROLLBAR,SBM_SETRANGE,0,10000); { int tabstop=21; //4 fixed chars SendDlgItemMessage(hwnd,IDC_CONTEXT,EM_SETTABSTOPS,1,&tabstop); } set_context_font(hwnd); open_file(&gfh); if(gfh==0){ WCHAR str[MAX_PATH*2]; _snwprintf(str,sizeof(str)/sizeof(WCHAR),L"cant open %s",fname); str[sizeof(str)/sizeof(WCHAR)-1]=0; MessageBoxW(hwnd,str,L"error",MB_OK); EndDialog(hwnd,0); return 0; } get_file_size(gfh,&fsize); _fseeki64(gfh,start_offset,SEEK_SET); set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh); SetFocus(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR)); line_count=get_number_of_lines(hwnd,IDC_CONTEXT); fill_context(hwnd,IDC_CONTEXT,gfh); close_file(&gfh); last_pos=-1; orig_edit=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,subclass_edit); orig_scroll=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR),GWL_WNDPROC,subclass_scroll); SetWindowTextW(hwnd,fname); return 0; case WM_DESTROY: save_context_rel_pos(hwnd); break; case WM_HELP: context_help(hwnd); return TRUE; break; case WM_SIZE: grippy_move(hwnd,grippy); set_context_divider(hwnd,row_width); line_count=get_number_of_lines(hwnd,IDC_CONTEXT); open_file(&gfh); fill_context(hwnd,IDC_CONTEXT,gfh); set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh); close_file(&gfh); break; case WM_RBUTTONDOWN: case WM_LBUTTONUP: ReleaseCapture(); if(divider_drag){ write_ini_value("CONTEXT_WINDOW","row_width",row_width); divider_drag=FALSE; } break; case WM_LBUTTONDOWN: SetCapture(hwnd); SetCursor(LoadCursor(NULL,IDC_SIZEWE)); divider_drag=TRUE; org_row_width=row_width; break; case WM_MOUSEFIRST: { int x=LOWORD(lparam); SetCursor(LoadCursor(NULL,IDC_SIZEWE)); if(divider_drag){ RECT rect; GetClientRect(hwnd,&rect); if((rect.right-x)>25 && x>5){ row_width=x; set_context_divider(hwnd,row_width); } } } break; case WM_MOUSEWHEEL: { short wheel=HIWORD(wparam); int flags=LOWORD(wparam); if(wheel>0){ dir=-1; if(flags&MK_RBUTTON) lines=line_count-2; else lines=3+1; } else{ dir=1; if(flags&MK_RBUTTON) lines=line_count-2-1; else lines=3; } do_scroll=TRUE; } break; case WM_VSCROLL: { int pos=HIWORD(wparam); switch(LOWORD(wparam)){ case SB_TOP: if(GetKeyState(VK_CONTROL)&0x8000){ last_offset=0; current_line=1; } else{ last_offset=start_offset; //_fseeki64(f,start_offset,SEEK_SET); current_line=start_line; } lines=dir=0; do_scroll=TRUE; break; case SB_PAGEUP: dir=-1; lines=line_count-2; if(lines<=0) lines=1; do_scroll=TRUE; break; case SB_PAGEDOWN: dir=1; lines=line_count-2-1; if(lines<=0) lines=1; do_scroll=TRUE; break; case SB_LINEUP: dir=-1; lines=2; do_scroll=TRUE; break; case SB_LINEDOWN: dir=1; lines=1; do_scroll=TRUE; break; case SB_THUMBTRACK: //printf("pos=%i last_pos=%i scroll_pos=%i line_count=%i\n",HIWORD(wparam),last_pos,scroll_pos,line_count); if(pos<last_pos){ dir=-1; lines=line_count/4; if(lines<=1) lines=2; do_scroll=TRUE; } else if(pos>last_pos){ dir=1; lines=line_count/4; if(lines==0) lines=1; do_scroll=TRUE; } if(last_pos==-1) do_scroll=FALSE; last_pos=pos; update_scroll_pos=FALSE; break; case SB_THUMBPOSITION: //dragged and released dir=lines=0; do_scroll=TRUE; break; case SB_ENDSCROLL: last_pos=-1; break; } } break; case WM_COMMAND: switch(LOWORD(wparam)){ case IDCANCEL: if(divider_drag){ divider_drag=FALSE; ReleaseCapture(); set_context_divider(hwnd,org_row_width); row_width=org_row_width; return 0; } if(gfh!=0) fclose(gfh); gfh=0; if(orig_edit!=0)SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,orig_edit); EndDialog(hwnd,0); return 0; } break; } if(do_scroll) do_scroll_proc(hwnd,lines,dir,update_scroll_pos); return 0; }