⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processing.ml

📁 是一个手机功能的模拟程序
💻 ML
字号:
open Freetype
open R2d_font
open Coding

let ti_metrics vertical =
if vertical then
{ascent= 8;
  descent= 0;
  leading= 0;
  max_width= 1536;
  max_height= 8;
  underline= -1;
  max_char_size= 6} (* max_char_size is always the width since the height is given
                       by ascent+descent+leading *)
else
  {ascent= 8;
  descent= 0;
  leading= 0;
  max_width= 6;
  max_height= 2048;
  underline= -1;
  max_char_size= 6}

(* Compute metrics for a face *)
let compute_metrics blocks the_face vertical = 
 let missing = ref false
 and c_max_width= ref 0
 and c_max_height=ref 0
 and c_max_char_size= ref 0  
 and iterator = new_iterator blocks in

 (* Iterate on all win latin 1 chars *)
 (try
 while true do
 let i=iterator();in
   let glyph_index = get_char_index the_face ( i) in 

   (* Generate a glyph with given settings *)
   load_glyph the_face glyph_index [LOAD_RENDER;
                                  LOAD_MONOCHROME;
                                  LOAD_FORCE_AUTOHINT];

   let glyph_data = get_glyph the_face in
   
   (* If glyph does not exists then replace it with the missing glyph
      which is glyph 0 *)
   if ((glyph_index=0) && (not !missing)) || (glyph_index != 0) then
   begin
         if (glyph_index = 0) then 
           missing:=true;
         if vertical then
         begin
           c_max_width := !c_max_width + get_width glyph_data;
           
         end else
         begin
           c_max_height := !c_max_height + get_height glyph_data;
           
         end;

         if (get_width glyph_data) > !c_max_char_size then
             c_max_char_size := get_width glyph_data;
   end;
   if vertical then
   begin
     if (get_height glyph_data) > !c_max_height then
     c_max_height := get_height glyph_data;
   end else
   begin
     if (get_width glyph_data) > !c_max_width then
     c_max_width := get_width glyph_data;
   end
 done;
 with End_iteration -> ()
 );

 {ascent= get_ascent the_face;
  descent= get_descent the_face;
  leading= get_face_height the_face - (get_ascent the_face) - (get_descent the_face);
  max_width= !c_max_width;
  max_height= !c_max_height;
  underline= get_underline the_face;
  max_char_size= !c_max_char_size}

let debug_ti_display the_metrics reversex reversey vertical =
  let x = ref 0 in

  (* Display bitmap of the glyph*)
  let display_bitmap m i =
    if vertical then
    begin
      for y=0 to (get_matrix_aligned_size m) - 1 do
        Printf.printf "%02d :" y;
        for x=0 to (get_matrix_size m) - 1 do
         if (get_matrix_element m x y) = 1 then
           Printf.printf "*"
         else
           Printf.printf " "
         
        done;
        Printf.printf "\n";
      done;
    end else
    begin
      
      for y=0 to (get_matrix_size m) - 1 do
        Printf.printf "%02d :" y;
        for x=0 to (get_matrix_aligned_size m) - 1 do
         
         if (get_matrix_element m x y) = 1 then
           Printf.printf "*"
         else
           Printf.printf " " 
         
        done;
        Printf.printf "\n";
      done;
    end;

    Printf.printf "-------------------------------------\n"  in
  Printf.printf "Font infos\n==========\n\n";
  if vertical then
  Printf.printf "ascent=%d,descent=%d,leading=%d,height=%d\n"
    the_metrics.ascent the_metrics.descent the_metrics.leading
    the_metrics.max_height
  else
  Printf.printf "ascent=%d,descent=%d,leading=%d,width=%d\n"
    the_metrics.ascent the_metrics.descent the_metrics.leading
    the_metrics.max_width;
  Printf.printf "------------------------------------------------------------\n";

  let iterator = new_iterator [BASIC_LATIN1] in
  try
  while true do
  let i=iterator() in
    let glyph_index = i in 
   
    (* Get bitmap defined in the glyph *)
    let m = R2d_font.extract_ti_bitmap i 8 reversex reversey vertical in
(* Display bitmap *)
    display_bitmap m i;

    (* Convert bitmap to LCD format : returns a list of words*)
     let b=Lcd.compact_matrix m  in
        let p a =
          match a with
            Lcd.WORD32(ah,al) -> Printf.printf "%04X%04X " ah al in
        List.iter p (List.rev b);
        Printf.printf "\n"; 
     Printf.printf "x=%d\n\n" !x;
     x := !x + 1;
    
  done;
  with End_iteration -> ()


(* Debug display of the char *)
let debug_display  block the_face the_metrics reversex reversey vertical = 
  let x = ref 0 in

  (* Display bitmap of the glyph*)
  let display_bitmap m i =
    let the_glyph = (get_glyph the_face) in
    Printf.printf "Unicode=%08X, Windows Latin1 = %08X\n"
         ( i) i;
    Printf.printf "char width=%d, char height = %d\n" 
         (get_width the_glyph) (get_height the_glyph);
    Printf.printf "adv_x=%d, adv_y=%d \n"
         (get_x_advance the_glyph) (get_y_advance the_glyph);
    Printf.printf "org_x=%d, org_y=%d \n"
         (get_left_origin the_glyph) (get_top_origin the_glyph);
    
    if vertical then
    begin
      for y=0 to (get_matrix_aligned_size m) - 1 do
        Printf.printf "%02d :" y;
        for x=0 to (get_matrix_size m) - 1 do
         if (get_matrix_element m x y) = 1 then
           Printf.printf "*"
         else
           Printf.printf " "
         
        done;
        Printf.printf "\n";
      done;
    end else
    begin
      
      for y=0 to (get_matrix_size m) - 1 do
        Printf.printf "%02d :" y;
        for x=0 to (get_matrix_aligned_size m) - 1 do
         
         if (get_matrix_element m x y) = 1 then
           Printf.printf "*"
         else
           Printf.printf " " 
         
        done;
        Printf.printf "\n";
      done;
    end;

    Printf.printf "-------------------------------------\n"  in
  Printf.printf "Font infos\n==========\n\n";
  if vertical then
  Printf.printf "ascent=%d,descent=%d,leading=%d,height=%d\n"
    the_metrics.ascent the_metrics.descent the_metrics.leading
    the_metrics.max_height
  else
  Printf.printf "ascent=%d,descent=%d,leading=%d,width=%d\n"
    the_metrics.ascent the_metrics.descent the_metrics.leading
    the_metrics.max_width;
  Printf.printf "------------------------------------------------------------\n";

  let iterator = new_iterator block in
  try
  while true do
  let i=iterator() in
    let glyph_index = get_char_index the_face ( i) in 
    load_glyph the_face glyph_index [LOAD_RENDER;
                                  LOAD_MONOCHROME;
                                  LOAD_FORCE_AUTOHINT];
    (* Get bitmap defined in the glyph *)
    let m = if vertical then
       expand_bitmap (get_glyph the_face) the_metrics.max_height reversex reversey ~vertical:vertical
    else
       expand_bitmap (get_glyph the_face) the_metrics.max_width reversex reversey ~vertical:vertical in

(* Display bitmap *)
    display_bitmap m i;

    (* Convert bitmap to LCD format : returns a list of words*)
     let b=Lcd.compact_matrix m  in
        let p a =
          match a with
            Lcd.WORD32(ah,al) -> Printf.printf "%04X%04X " ah al in
        List.iter p (List.rev b);
        Printf.printf "\n"; 
     Printf.printf "x=%d\n\n" !x;
     x := !x + 1;
    
  done;
  with End_iteration -> ()
  


let generate_font f f_m f_b f_t name vertical =
 let pword a = match a with
            Lcd.WORD32(ah,al) -> Printf.fprintf f_b "0x%04X%04X,\n" ah al in
 Printf.fprintf f_b "const UINT32 r2d_font_bitmap_%s[]={\n" name;
 List.iter pword (List.rev f.framebuffer);
 Printf.fprintf f_b "};\n";
 let x =ref 0
 and sizew = ref 0
 and missing = ref false 
 and missing_pos = ref 0 in
 let pmetrics m =
   if ((m.glyph_index=0) && (not !missing)) || (m.glyph_index != 0) then
   begin
         if (m.glyph_index = 0) then 
         begin
           missing := true;
           missing_pos := !x;
         end;
         Printf.fprintf f_m "%d,%d,%d,%d,%d,%d,%d,%d,\n" m.glyph_index 
           !x m.width m.height m.x_advance m.y_advance m.x_org m.y_org;
         if vertical then
           x := !x + m.width 
         else
           x := !x + m.height 
   end else
    Printf.fprintf f_m "%d,%d,%d,%d,%d,%d,%d,%d,\n" m.glyph_index 
           !missing_pos 
           m.width m.height m.x_advance m.y_advance m.x_org m.y_org in

 Printf.fprintf f_m "const INT32 r2d_font_metric_%s[]={\n" name;
 Printf.fprintf f_m "%d, /* Font framebuffer width in pixels */\n" f.global_metrics.max_width;
 Printf.fprintf f_m "%d, /* Font framebuffer height in pixels */\n" f.global_metrics.max_height;
 sizew := if vertical then Lcd.get_lcd_size_in_words f.global_metrics.max_height 
  else Lcd.get_lcd_size_in_words f.global_metrics.max_width;
 Printf.fprintf f_m "%d, /* Font framebuffer aligned size in Word32 */\n" !sizew;
 Printf.fprintf f_m "%d, /* Font free area for char creation */\n" f.global_metrics.max_char_size;
 Printf.fprintf f_m "%d, /* Font ascent in pixels */\n" f.global_metrics.ascent;
 Printf.fprintf f_m "%d, /* Font descent in pixels */\n" f.global_metrics.descent;
 Printf.fprintf f_m "%d, /* Font leading in pixels */\n" f.global_metrics.leading;
 Printf.fprintf f_m "%d, /* Font underline in pixels */\n" f.global_metrics.underline;
 Printf.fprintf f_m "/* glyph_index, x position in framebuffer, char width, char height\n";
 Printf.fprintf f_m "   x davance, y advance, char x origin, char y origin */\n";
 List.iter pmetrics (List.rev f.local_metrics);
 Printf.fprintf f_m "};\n";
 Printf.fprintf f_t "const INT32 r2d_font_ptree_%s[]={\n" name;
 Ptset.fprint_tree f_t f.transcodage;
 Printf.fprintf f_t "};\n"




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -