The name and size of the current font in the status bar.

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

The name and size of the current font in the status bar.

Post by sexy96 »

Jak uzyskać nazwę aktualnego fontu i wielkość na dolnym pasku (stanu)

Code: Select all

var hEditWnd = AkelPad.GetEditWnd();
var hFont;

if (hEditWnd)
{
   hFont    = AkelPad.SendMessage(hEditWnd, 0x0031 /*WM_GETFONT*/, 0, 0);
}
hFont pokazuje dla: "Courier New 11" numer: 2114594013
a dla: "Arial 11", taki numer: 772416358
Jak to zamienić na nazwę i wielkość
StatusUserFormat= nazwa? wielkość?

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

sexy96

Code: Select all

var hEditWnd = AkelPad.GetEditWnd();
var hFont;
var aFont;

if (hEditWnd)
{
  hFont = AkelPad.SendMessage(hEditWnd, 0x0031 /*WM_GETFONT*/, 0, 0);
  aFont = GetFontArray(hFont, hEditWnd);

  WScript.Echo("Font name: "  + aFont[0] + "\n" +
               "Font style: " + aFont[1] + "\n" +
               "Font size: "  + aFont[2]);
}

function GetFontArray(hFont, hWnd)
{
  var oSys    = AkelPad.SystemFunction();
  var nLFSize = 28 + 32 * 2; //sizeof(LOGFONTW)
  var lpLF    = AkelPad.MemAlloc(nLFSize);
  var hDC     = oSys.Call("User32::GetDC", hWnd);
  var aFont   = [];
  var nHeight;
  var nWeight;
  var bItalic;

  oSys.Call("Gdi32::GetObjectW", hFont, nLFSize, lpLF);

  nHeight  = AkelPad.MemRead(_PtrAdd(lpLF,  0), 3 /*DT_DWORD*/);   //lfHeight
  nWeight  = AkelPad.MemRead(_PtrAdd(lpLF, 16), 3 /*DT_DWORD*/);   //lfWeight
  bItalic  = AkelPad.MemRead(_PtrAdd(lpLF, 20), 5 /*DT_BYTE*/);    //lfItalic
  aFont[0] = AkelPad.MemRead(_PtrAdd(lpLF, 28), 1 /*DT_UNICODE*/); //lfFaceName
  aFont[2] = -oSys.Call("Kernel32::MulDiv", nHeight, 72, oSys.Call("Gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/));

  if (nWeight < 600)
    aFont[1] = 1;
  else
    aFont[1] = 2;

  if (bItalic)
    aFont[1] += 2;

  oSys.Call("User32::ReleaseDC", hWnd, hDC); 
  AkelPad.MemFree(lpLF);

  return aFont;
}


Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post by sexy96 »

StatusUserFormat=/Call("Scripts::Main", 1, "GetFontArray.js", 'aFont[0] + " " + aFont[2]')

Coś tu mam nieprawidłowo wpisane (nie działa).

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

sexy96
Ja tylko podałem przykład, w jaki sposób uzyskać parametry czcionki.
Natomiast nie ma możliwości umieszczenia na pasku statusu nazwy aktualnie używanej czcionki (w ten sposób, żeby się aktualizowała po zmianie czcionki).
Można tylko podać rozmiar czcionki:
StatusUserFormat=Font size: %f

Instructor
Could you add in StatusUserFormat a parameter for font name, eg: %fn.

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post by sexy96 »

%f jest OK
Wielkie dzięki.

Niestety %fn nie działa.
Post Reply