Page 1 of 1

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

Posted: Fri Sep 16, 2016 10:46 am
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ść?

Posted: Fri Sep 16, 2016 5:22 pm
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;
}


Posted: Sat Sep 17, 2016 8:13 am
by sexy96
StatusUserFormat=/Call("Scripts::Main", 1, "GetFontArray.js", 'aFont[0] + " " + aFont[2]')

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

Posted: Sat Sep 17, 2016 2:30 pm
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.

Posted: Sat Sep 17, 2016 4:30 pm
by sexy96
%f jest OK
Wielkie dzięki.

Niestety %fn nie działa.