線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1642
推到 Plurk!
推到 Facebook!

有關 windows LOG Font 的使用

答題得分者是:hagar
小蚊子
中階會員


發表:55
回覆:267
積分:94
註冊:2002-06-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-06-14 10:58:38 IP:210.244.xxx.xxx 未訂閱
請問網友: 1. 指定字型時,出現錯誤 aFont[1] := '標楷體'; aFont[2] := '新細明體'; ..... lf.lfFaceName := aFont[ 2 ]; 出現 [Error] font1u.pas(283): Incompatible types: 'Array' and 'String' 但是若用 以下直接給值方式,就可以 lf.lfFaceName := '新細明體'; aFont[2] 的內容不就是 新細明體 嗎 ?? 為何無法直接給值 ?? 2. 有關角度的設定,以下二屬性,不知如何使用 ?? lf.lfEscapement:= 900 ; // 0-正常 900-轉90 度 lf.lfOrientation:= 900; // // 0-正常 900-轉90 度 此二屬性,給了 900 的值,似乎無法動作, 還是我少了哪些動作 ??? 3. lfHeight : 看見某 vb 資料說明如下 這是字元高度 這個值得算法如下 lfHeight = -FontSize * GetDeviceCaps(hdc, LOGPIXELSY) / 72 FontSize是字型的點數 a. 不知 它的意思是???? 為何要 除 72 ??? b. 此語法轉為 delphi ,不知如何下達??? 謝謝您的回答 !!
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-06-14 11:46:04 IP:202.39.xxx.xxx 未訂閱
1.用 StrPCopy 的方式,例: StrPCopy (lf.lfFaceName, aFont[2]); 2.小弟這邊兩個值都給 900, 可以動作 3. a.所謂 TFont.Size 的 Size 是以點計算,一點是指 1/72 英吋(所以除以 72) 而 TFont.Height 則是以像素(pixel)來計算, 兩者間轉換的公式為: TFont.Height := TFont.Size * TFont.PixelsPerInch / 72 參考: http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q74/2/99.asp&NoWebContent=1 另外 Delphi 於繪圖與圖形處理上的實習應用一書第 27 頁有更詳細的說明 b. lf.lfHeight := Trunc(-Form1.Font.Size * GetDeviceCaps(Form1.Canvas.handle, LOGPIXELSY) / 72);
小蚊子
中階會員


發表:55
回覆:267
積分:94
註冊:2002-06-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-06-14 17:30:44 IP:203.73.xxx.xxx 未訂閱
引言: 2.小弟這邊兩個值都給 900, 可以動作
hagar 前輩: 我試了 900 這數據,還是無法轉向??? 您可以幫我檢查一下嗎?? 謝謝您了 = = = = = = = = = = = = = = procedure TForm1.Button4Click(Sender: TObject); var i, xPos, iTxtWidth : integer; bmp : TBitmap; str , sfont : string; lf : TLogFont; nSize,nSizeH,nSizeW : integer; begin // help // http://www.hosp.ncku.edu.tw/~cww/html/q00367.html sfont := '新細明體'; // '標楷體'; nSizeH := 50; nSizeW := 30; GetObject(Form1.Font.Handle, SizeOf(TLogFont), @lf); bmp := TBitmap.Create; str := '北市四維南路23段415號九樓B室'; try i := 1; xPos := 0; bmp.Width := 1400; // 先預設一張大的空白圖 bmp.Height := 60; // 預設圖高度 while i <= Length(str) do begin if IsDBCSLeadByte(Byte(str[i])) then begin lf.lfWidth := nSizeW; lf.lfHeight := nSizeH; StrPCopy(lf.lfFaceName,sfont); // lf.lfEscapement := 0; lf.lfOrientation := 900; // 字轉 90 度 lf.lfItalic:=0; // 0 正常 1:斜體 bmp.Canvas.Font.Handle := CreateFontIndirect(lf); bmp.Canvas.TextOut(xPos, 0, str[i] + str[i+1]); iTxtWidth := bmp.Canvas.TextWidth(str[i] + str[i+1]); Inc(i, 2); end else begin lf.lfWidth := nSizeW; lf.lfHeight := nSizeH; lf.lfFaceName := 'Arial'; // lf.lfEscapement := 0; // lf.lfOrientation := 0; lf.lfItalic := 0; bmp.Canvas.Font.Handle := CreateFontIndirect(lf); bmp.Canvas.TextOut(xPos, 0, str[i]); iTxtWidth := bmp.Canvas.TextWidth(str[i]); Inc(i); end; xPos := xPos + iTxtWidth; end; bmp.Width := xPos; // 有圖的區域才存檔 bmp.Height := bmp.Height; bmp.SaveToFile('_font4.bmp'); finally bmp.Free; end; end; 發表人 - 小蚊子 於 2004/06/14 17:35:13
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-06-14 17:57:09 IP:202.39.xxx.xxx 未訂閱
看一下紅色的部份:
var
  i, xPos, iTxtWidth : integer;
  bmp : TBitmap;
  str , sfont : string;
  lf : TLogFont;
  nSize,nSizeH,nSizeW : integer;
begin
  // help
  // http://www.hosp.ncku.edu.tw/~cww/html/q00367.html      sfont := '新細明體'; // '標楷體';
  nSizeH := 50;
  nSizeW := 30;      GetObject(Form1.Font.Handle, SizeOf(TLogFont), @lf);
  bmp := TBitmap.Create;
  str := '北市四維南路23段415號九樓B室';
  try
    i := 1;
    xPos := 0;        bmp.Width := 1400; // 先預設一張大的空白圖
    bmp.Height := 60; // 預設圖高度        while i <= Length(str) do
    begin
      if IsDBCSLeadByte(Byte(str[i])) then
      begin
        lf.lfWidth := nSizeW;
        lf.lfHeight := nSizeH;            StrPCopy(lf.lfFaceName,sfont);
        lf.lfEscapement := 900; // 這行不可 mark 掉
        lf.lfOrientation := 900; // 字轉 90 度(這行可要可不要,要的時候值須與 lfEscapement 相同)
        lf.lfItalic:=0; // 0 正常 1:斜體
        bmp.Canvas.Font.Handle := CreateFontIndirect(lf);            bmp.Canvas.TextOut(xPos, 60, str[i]   str[i 1]); // x 座標從最底層開始畫,才不會轉了 90 度後,字都看不見了
        iTxtWidth := bmp.Canvas.TextWidth(str[i]   str[i 1]);
        Inc(i, 2);
      end
      else
      begin
        lf.lfWidth := nSizeW;
        lf.lfHeight := nSizeH;
        lf.lfFaceName := 'Arial';            lf.lfEscapement := 0; // 這行不拿掉
        //lf.lfOrientation := 0; // 這行可拿掉
        lf.lfItalic := 0;
        bmp.Canvas.Font.Handle := CreateFontIndirect(lf);            bmp.Canvas.TextOut(xPos, 0, str[i]);
        iTxtWidth := bmp.Canvas.TextWidth(str[i]);
        Inc(i);
      end;
      xPos := xPos   iTxtWidth;        end;        bmp.Width := xPos; // 有圖的區域才存檔
    bmp.Height := bmp.Height;        bmp.SaveToFile('_font4.bmp');      finally
    bmp.Free;
  end;
end;
小蚊子
中階會員


發表:55
回覆:267
積分:94
註冊:2002-06-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-06-14 18:53:43 IP:210.244.xxx.xxx 未訂閱
引言: StrPCopy(lf.lfFaceName,sfont); lf.lfEscapement := 900; // 這行不可 mark 掉 lf.lfOrientation := 900; // 字轉 90 度(這行可要可不要,要的時候值須與 lfEscapement 相同) lf.lfItalic:=0; // 0 正常 1:斜體 bmp.Canvas.Font.Handle := CreateFontIndirect(lf); bmp.Canvas.TextOut(xPos, 60, str[i] str[i 1]); // x 座標從最底層開始畫,才不會轉了 90 度後,字都看不見了 iTxtWidth := bmp.Canvas.TextWidth(str[i] str[i 1]); Inc(i, 2); end else begin lf.lfWidth := nSizeW; lf.lfHeight := nSizeH; lf.lfFaceName := 'Arial'; lf.lfEscapement := 0; // 這行不拿掉
原來它的起始點,已經不是左上角,我又學到一招,謝謝您了.
系統時間:2024-05-06 0:14:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!