| View previous topic :: View next topic |
| Author |
Message |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Sun Jun 03, 2012 1:38 pm Post subject: |
|
|
Instructor
Случайно выбрал bold, начал переключать, он так жирным и остается. А если в последней строке
AkelPad.Font(lpFontList[i][0], 0, lpFontList[i][1]);
0 на 1 заменить, то универсальность идеи теряется. Может еще ввести параметр типа(жирный, косой, без изменений и тп)? Не сочтите что я обнаглел, просто мысли)) Мне и первый вариант нравился. |
|
| Back to top |
|
 |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Sun Jun 03, 2012 2:19 pm Post subject: |
|
|
Не знаю, есть ли смысл доставать данные о типе шрифта из программы и сравнивать со списком, да и не знаю откуда и как их доставать. Себе просто эти данные добавил.
Текст | Code: | // http://akelpad.sourceforge.net/forum/viewtopic.php?p=18278#18278
// Version v1.2 mod
//
//
//// Cycle switch between fonts.
//Options
var lpFontList=[["MS Sans Serif", 1, 8],
["Courier New", 3, 10],
["Arial", 2, 9],
["Courier New", 4, 8]];
//Variables
var hMainWnd=AkelPad.GetMainWnd();
var hWndEdit=AkelPad.GetEditWnd();
var lpLogFont;
var pFontName="";
var nFontSize=0;
var i;
if (lpLogFont=AkelPad.MemAlloc(92 /*sizeof(LOGFONTW)*/))
{
AkelPad.SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, hWndEdit, lpLogFont);
pFontName=AkelPad.MemRead(lpLogFont + 28 /*offsetof(LOGFONTW, lfFaceName)*/, 1 /*DT_UNICODE*/);
nFontSize=AkelPad.SendMessage(hWndEdit, 3188 /*AEM_GETCHARSIZE*/, 3 /*AECS_POINTSIZE*/, 0);
AkelPad.MemFree(lpLogFont);
}
if (pFontName && nFontSize)
{
for (i=0; i < lpFontList.length; ++i)
{
if (lpFontList[i][0] == pFontName && lpFontList[i][2] == nFontSize)
break;
}
if (++i >= lpFontList.length) i=0;
AkelPad.Font(lpFontList[i][0], lpFontList[i][1], lpFontList[i][2]);
} |
|
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
Posted: Sun Jun 03, 2012 2:19 pm Post subject: |
|
|
Visitor7
Try this script:
FontCycleSwitch.js |
|
| Back to top |
|
 |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Sun Jun 03, 2012 3:13 pm Post subject: |
|
|
KDJ
Интересный вариант. Когда открываю текст именно вашего скрипта, раскрываю окно на полный экран и прохожу несколько циклов смены шрифтов, отображение текста начинает страшно глючить.
Картинка
Нажатие F5 спасает. |
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
Posted: Sun Jun 03, 2012 4:01 pm Post subject: |
|
|
Visitor7
Fixed.
The script must be saved in ANSI format. |
|
| Back to top |
|
 |
Infocatcher
Joined: 06 Aug 2007 Posts: 1439
|
Posted: Mon Jun 04, 2012 8:57 am Post subject: |
|
|
Можно как-нибудь починить возможность доступа к глобальному объекту?
| Code: | var global = this;
global.x = {};
WScript.Echo(x); |
Выдает | Quote: | Ошибка: Объект не поддерживает это свойство или метод
Код: 800A01B6
Источник: Ошибка выполнения Microsoft JScript |
А если запустить через wscript.exe, то работает.
Полезно при создании библиотек или использовании чужого кода с кучей глобальных переменных.
Как-то так:
| Code: | (function() {
var foo = 1;
var bar = 2;
this.f = function() {
return foo + bar;
}
})();
WScript.Echo(f());
WScript.Echo(typeof foo); // "undefined" |
|
|
| Back to top |
|
 |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Mon Jun 04, 2012 11:22 am Post subject: |
|
|
KDJ
Глюк исчез в режиме "развернуть на весь экран", но остался в режиме "полный экран".
Instructor
А как получить FontType из Akelpad, ну подобно как вы брали
pFontName=AkelPad.MemRead(lpLogFont + 28 /*offsetof(LOGFONTW, lfFaceName)*/, 1 /*DT_UNICODE*/);
nFontSize=AkelPad.SendMessage(hWndEdit, 3188 /*AEM_GETCHARSIZE*/, 3 /*AECS_POINTSIZE*/, 0);
Не дает мне покоя этот вопрос)) |
|
| Back to top |
|
 |
VladSh
Joined: 29 Nov 2006 Posts: 2521 Location: Киев, Русь
|
Posted: Mon Jun 04, 2012 11:23 am Post subject: |
|
|
KDJ
In this script, use ini-file would not be superfluous, because the since store settings/data with the code is a perversion. |
|
| Back to top |
|
 |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Mon Jun 04, 2012 12:15 pm Post subject: |
|
|
KDJ
А, я понял. Глюк остался как был, но зависит от того, на каком мониторе раскрывать на полный экран. У меня два, 2-ой главный, на нем глюк отображения и происходит при раскрытии на поный экран или развороте на весь экран(после применения вашего скрипта). А на 1-м не главном мониторе растягивается на весь экран нормально, а в полноэкранный режим вообще не переходит, Akelpad ведь не поддерживает пока мультимонитор.
А вообще, ваш вариант интересен тем, что при больших списках шрифтов может дать большую производительность. Вариант Инструктора каждый раз перебирает список, а ваш каждый раз пишет на диск. При малом списке перебор в разы быстрее записи. |
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
Posted: Mon Jun 04, 2012 5:39 pm Post subject: |
|
|
| Visitor7 wrote: | ...
А как получить FontType из Akelpad, ну подобно как вы брали
pFontName=AkelPad.MemRead(lpLogFont + 28 /*offsetof(LOGFONTW, lfFaceName)*/, 1 /*DT_UNICODE*/);
...
|
FontType can be read from lpLogFont structure:
| Code: | var nWeight = AkelPad.MemRead(lpLogFont + 16 /*offsetof(LOGFONTW, lfWeight)*/, 3 /*DT_DWORD*/);
var bItalic = AkelPad.MemRead(lpLogFont + 20 /*offsetof(LOGFONTW, lfItalic)*/, 5 /*DT_BYTE*/);
var nFontType;
if (nWeight < 600)
nFontType = 1;
else
nFontType = 2;
if (bItalic)
nFontType += 2; |
|
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
Posted: Mon Jun 04, 2012 8:16 pm Post subject: |
|
|
ChooseFont_function.js
Changed: now dialog box is centered in parent window. |
|
| Back to top |
|
 |
Visitor7
Joined: 03 Jun 2012 Posts: 88
|
Posted: Mon Jun 04, 2012 11:52 pm Post subject: |
|
|
KDJ
Спасибо, как-то так сделал, вроде все работает:
Текст | Code: | // http://akelpad.sourceforge.net/forum/viewtopic.php?p=18278#18278
// Version v1.2 mod2
//
//
//// Cycle switch between fonts.
//Options
var lpFontList=[["MS Sans Serif", 1, 7],
["Courier New", 3, 10],
["Tahoma", 2, 10],
["Lucida Console", 4, 13],
["Arial", 0, 11]];
//Variables
var hMainWnd=AkelPad.GetMainWnd();
var hWndEdit=AkelPad.GetEditWnd();
var lpLogFont;
var pFontName="";
var nWeight;
var bItalic;
var nFontType;
var nFontSize=0;
var i;
if (lpLogFont=AkelPad.MemAlloc(92 /*sizeof(LOGFONTW)*/))
{
AkelPad.SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, hWndEdit, lpLogFont);
pFontName=AkelPad.MemRead(lpLogFont + 28 /*offsetof(LOGFONTW, lfFaceName)*/, 1 /*DT_UNICODE*/);
nWeight = AkelPad.MemRead(lpLogFont + 16 /*offsetof(LOGFONTW, lfWeight)*/, 3 /*DT_DWORD*/);
bItalic = AkelPad.MemRead(lpLogFont + 20 /*offsetof(LOGFONTW, lfItalic)*/, 5 /*DT_BYTE*/);
nFontSize=AkelPad.SendMessage(hWndEdit, 3188 /*AEM_GETCHARSIZE*/, 3 /*AECS_POINTSIZE*/, 0);
AkelPad.MemFree(lpLogFont);
}
if (pFontName && nWeight && nFontSize)
{
if (nWeight < 600)
nFontType = 1;
else
nFontType = 2;
if (bItalic)
nFontType += 2;
for (i=0; i < lpFontList.length; ++i)
{
if (!lpFontList[i][1])
lpFontList[i][1]=nFontType;
if (lpFontList[i][0] == pFontName && lpFontList[i][1]==nFontType && lpFontList[i][2] == nFontSize)
break;
}
if (++i >= lpFontList.length) i=0;
AkelPad.Font(lpFontList[i][0], lpFontList[i][1], lpFontList[i][2]);
} |
Я был не прав, это не ваш скрипт глючил, а функция Akelpad перерисовки экрана при смене шрифта.
Назначаю горячие клавиши:
Font 1 --- Font("Courier New", 1, 8 ) --- Alt+1
Font 2 --- Font("Arial", 1, 17) ------------ Alt+2
Разрешение монитора 1024x768, Akelpad развернут на полный экран, перенос по словам включен(с выключенным нормально). Раскрытый в Akelpad текст:
сам текст | Code: | // FontCycleSwitch.js - ver. 2012-06-03a
//
// Cycle switch between fonts. Alternative version of FontSwitch.js by Instructor.
//
// Call("Scripts::Main", 1, "FontCycleSwitch.js")
//
// Note: This script modifies itself
//here you can insert the desired fonts:
var aFonts = [
["Courier New", 0, 11],
["MS Sans Serif", 1, 7],
["Tahoma", 2, 9],
["Lucida Console", 3, 12],
["Arial", 4, 15]
];
//////////////
var nFont = 2;
if (nFont >= aFonts.length)
nFont = 0;
AkelPad.Font(aFonts[nFont][0], aFonts[nFont][1], aFonts[nFont][2]);
var sScrFile = WScript.ScriptFullName;
var sScrText = AkelPad.ReadFile(sScrFile).replace(/(var\s+nFont\s*=\s*)(\d+)(\s*;)/, "$1" + ++nFont + "$3");
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var oFile = oFSO.OpenTextFile(sScrFile, 2, true, 0);
oFile.Write(sScrText);
oFile.Close(); |
После нескольких нажатий на Alt+1, Alt+2, Alt+1, Alt+2, Alt+1, Alt+2.... получаю на экране такой результат:
Картинка. |
|
| Back to top |
|
 |
VladSh
Joined: 29 Nov 2006 Posts: 2521 Location: Киев, Русь
|
Posted: Tue Jun 05, 2012 8:47 am Post subject: |
|
|
KDJ
I meant to store it:
| Code: | "Courier New", 0, 11
"MS Sans Serif", 1, 17
"Tahoma", 2, 9
"Lucida Console", 3, 12
"Arial", 4, 15 | so that the user did not change the script, and changed the configuration file. |
|
| Back to top |
|
 |
KDJ
Joined: 06 Mar 2010 Posts: 1080 Location: Poland
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|