/*
* -----
* Screenshot Sender - __font.js
* -----
* This library allows you to change the font of specific controls. Made by phalanxii.
* URL: http://msghelp.net/showthread.php?tid=77717
* -----
*/
// Font weight constants
var FW_DONTCARE = 0;
var FW_THIN = 100;
var FW_EXTRALIGHT = 200;
var FW_LIGHT = 300;
var FW_NORMAL = 400;
var FW_MEDIUM = 500;
var FW_SEMIBOLD = 600;
var FW_BOLD = 700;
var FW_EXTRABOLD = 800;
var FW_HEAVY = 900;
var FW_ULTRALIGHT = FW_EXTRALIGHT;
var FW_REGULAR = FW_NORMAL;
var FW_DEMIBOLD = FW_SEMIBOLD;
var FW_ULTRABOLD = FW_EXTRABOLD;
var FW_BLACK = FW_HEAVY;
// Character set identifiers
var ANSI_CHARSET = 0;
var DEFAULT_CHARSET = 1;
var SYMBOL_CHARSET = 2;
var SHIFTJIS_CHARSET = 128;
var HANGEUL_CHARSET = 129;
var CHINESEBIG5_CHARSET = 136;
var OEM_CHARSET = 255;
var JOHAB_CHARSET = 130;
var HEBREW_CHARSET = 177;
var ARABIC_CHARSET = 178;
var GREEK_CHARSET = 161;
var TURKISH_CHARSET = 162;
var VIETNAMESE_CHARSET = 163;
var THAI_CHARSET = 222;
var EASTEUROPE_CHARSET = 238;
var RUSSIAN_CHARSET = 204;
var MAC_CHARSET = 77;
var BALTIC_CHARSET = 186;
// Output precision constants
var OUT_DEFAULT_PRECIS = 0;
var OUT_STRING_PRECIS = 1;
var OUT_CHARACTER_PRECIS = 2;
var OUT_STROKE_PRECIS = 3;
var OUT_TT_PRECIS = 4;
var OUT_DEVICE_PRECIS = 5;
var OUT_RASTER_PRECIS = 6;
var OUT_TT_ONLY_PRECIS = 7;
var OUT_OUTLINE_PRECIS = 8;
// Clipping precision constants
var CLIP_DEFAULT_PRECIS = 0;
var CLIP_CHARACTER_PRECIS = 1;
var CLIP_STROKE_PRECIS = 2;
var CLIP_MASK = 15;
var CLIP_LH_ANGLES = 1 << 4;
var CLIP_TT_ALWAYS = 2 << 4;
var CLIP_EMBEDDED = 8 << 4;
// Output quality constants
var DEFAULT_QUALITY = 0;
var DRAFT_QUALITY = 1;
var PROOF_QUALITY = 2;
var NONANTIALIASED_QUALITY = 3;
var ANTIALIASED_QUALITY = 4;
var CLEARTYPE_QUALITY = 5;
var CLEARTYPE_NATURAL_QUALITY = 6;
// Font pitch constants
var DEFAULT_PITCH = 0;
var FIXED_PITCH = 1;
var VARIABLE_PITCH = 2;
// Font family constants
var FF_DONTCARE = 0 << 4;
var FF_ROMAN = 1 << 4;
var FF_SWISS = 2 << 4;
var FF_MODERN = 3 << 4;
var FF_SCRIPT = 4 << 4;
var FF_DECORATIVE = 5 << 4;
// Message constants
var WM_SETFONT = 48;
var WM_GETFONT = 49;
// Choose font flags
var CF_SCREENFONTS = 1;
var CF_PRINTERFONTS = 2;
var CF_BOTH = CF_SCREENFONTS | CF_PRINTERFONTS;
var CF_SHOWHELP = 4;
var CF_ENABLEHOOK = 8;
var CF_ENABLETEMPLATE = 16;
var CF_ENABLETEMPLATEHANDLE = 32;
var CF_INITTOLOGFONTSTRUCT = 64;
var CF_USESTYLE = 128;
var CF_EFFECTS = 256;
var CF_APPLY = 512;
var CF_ANSIONLY = 1024;
var CF_SCRIPTSONLY = CF_ANSIONLY;
var CF_NOVECTORFONTS = 2048;
var CF_NOOEMFONTS = CF_NOVECTORFONTS;
var CF_NOSIMULATIONS = 4096;
var CF_LIMITSIZE = 8192;
var CF_FIXEDPITCHONLY = 16384;
var CF_WYSIWYG = 32768;
var CF_FORCEFONTEXIST = 65536;
var CF_SCALABLEONLY = 131072;
var CF_TTONLY = 262144;
var CF_NOFACESEL = 524288;
var CF_NOSTYLESEL = 1048576;
var CF_NOSIZESEL = 2097152;
var CF_SELECTSCRIPT = 4194304;
var CF_NOSCRIPTSEL = 8388608;
var CF_NOVERTFONTS = 16777216;
/*
* -----
* Class: Font
* Parameters:
* Height - [Integer] Specifies the height of characters in the font.
* Width - [Integer] Specifies the average width of characters in the font.
* Escapement - [Integer] Specifies the angle between the escapement vector and the x-axis of the device.
* Orientation - [Integer] Specifies the angle between the base line of each character and the x-axis of the device.
* Weight - [Integer] Specifies the weight of the font.
* Italic - [Boolean] Specifies whether the font is an italic font.
* Underline - [Boolean] Specifies whether the font is an underlined font.
* StrikeOut - [Boolean] Specifies whether the font is a strikeout font.
* CharSet - [Constant] Specifies the character set.
* OutPrecision - [Constant] Specifies the output precision.
* ClipPrecision - [Constant] Specifies the clipping precision.
* Quality - [Constant] Specifies the output quality.
* PitchAndFamily - [Constant] Specifies the pitch and family of the font.
* FaceName - [String] Specifies the typeface name of the font.
* -----
*/
function Font(Height, Width, Escapement, Orientation, Weight, Italic, Underline, StrikeOut, CharSet, OutPrecision, ClipPrecision, Quality, PitchAndFamily, FaceName, ColorRef) {
// Default options
this.Height = 0;
this.Width = 0;
this.Escapement = 0;
this.Orientation = 0;
this.Weight = FW_DONTCARE;
this.Italic = false;
this.Underline = false;
this.StrikeOut = false;
this.CharSet = DEFAULT_CHARSET;
this.OutPrecision = OUT_DEFAULT_PRECIS;
this.ClipPrecision = CLIP_DEFAULT_PRECIS;
this.Quality = DEFAULT_QUALITY;
this.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
this.FaceName = 'MS Shell Dlg';
this.ColorRef = 0x0;
if(arguments.length === 1 && typeof(arguments[0]) === 'object') {
// Passed as source object
var oSrc = arguments[0];
if(typeof(oSrc.Height) === 'number') this.Height = oSrc.Height;
if(typeof(oSrc.Width) === 'number') this.Width = oSrc.Width;
if(typeof(oSrc.Escapement) === 'number') this.Escapement = oSrc.Escapement;
if(typeof(oSrc.Orientation) === 'number') this.Orientation = oSrc.Orientation;
if(typeof(oSrc.Weight) === 'number') this.Weight = oSrc.Weight;
if(typeof(oSrc.Italic) !== 'undefined') this.Italic = !!oSrc.Italic;
if(typeof(oSrc.Underline) !== 'undefined') this.Underline = !!oSrc.Underline;
if(typeof(oSrc.StrikeOut) !== 'undefined') this.StrikeOut = !!oSrc.StrikeOut;
if(typeof(oSrc.CharSet) === 'number') this.CharSet = oSrc.CharSet;
if(typeof(oSrc.OutPrecision) === 'number') this.OutPrecision = oSrc.OutPrecision;
if(typeof(oSrc.ClipPrecision) === 'number') this.ClipPrecision = oSrc.ClipPrecision;
if(typeof(oSrc.Quality) === 'number') this.Quality = oSrc.Quality;
if(typeof(oSrc.PitchAndFamily) === 'number') this.PitchAndFamily = oSrc.PitchAndFamily;
if(typeof(oSrc.FaceName) === 'string') this.FaceName = oSrc.FaceName;
if(typeof(oSrc.ColorRef) === 'number') this.ColorRef = oSrc.ColorRef;
} else {
// Passed as arguments
if(typeof(Height) === 'number') this.Height = Height;
if(typeof(Width) === 'number') this.Width = Width;
if(typeof(Escapement) === 'number') this.Escapement = Escapement;
if(typeof(Orientation) === 'number') this.Orientation = Orientation;
if(typeof(Weight) === 'number') this.Weight = Weight;
if(typeof(Italic) !== 'undefined') this.Italic = !!Italic;
if(typeof(Underline) !== 'undefined') this.Underline = !!Underline;
if(typeof(StrikeOut) !== 'undefined') this.StrikeOut = !!StrikeOut;
if(typeof(CharSet) === 'number') this.CharSet = CharSet;
if(typeof(OutPrecision) === 'number') this.OutPrecision = OutPrecision;
if(typeof(ClipPrecision) === 'number') this.ClipPrecision = ClipPrecision;
if(typeof(Quality) === 'number') this.Quality = Quality;
if(typeof(PitchAndFamily) === 'number') this.PitchAndFamily = PitchAndFamily;
if(typeof(FaceName) === 'string') this.FaceName = FaceName;
if(typeof(ColorRef) === 'number') this.ColorRef = ColorRef;
}
// Create a LOGFONT structure
this.LOGFONT = Interop.Allocate(92);
// Update the LOGFONT and HFONT
this.Update();
}
Font.prototype = {
// Update the LOGFONT and HFONT based on the font properties
'Update' : function () {
this.UpdateLOGFONT();
this.UpdateHFONT();
},
// Update the LOGFONT based on the font properties
'UpdateLOGFONT' : function () {
with (this.LOGFONT) {
WriteDWORD(0, this.Height);
WriteDWORD(4, this.Width);
WriteDWORD(8, this.Escapement);
WriteDWORD(12, this.Orientation);
WriteDWORD(16, this.Weight);
SetAt(20, (this.Italic) ? 1 : 0);
SetAt(21, (this.Underline) ? 1 : 0);
SetAt(22, (this.StrikeOut) ? 1 : 0);
SetAt(23, this.CharSet);
SetAt(24, this.OutPrecision);
SetAt(25, this.ClipPrecision);
SetAt(26, this.Quality);
SetAt(27, this.PitchAndFamily);
WriteString(28, this.FaceName, true);
}
},
// Update the HFONT based on the LOGFONT
'UpdateHFONT' : function () {
this.HFONT = Interop.Call('gdi32.dll', 'CreateFontIndirectW', this.LOGFONT.DataPtr);
this.Handle = this.HFONT;
},
// Update the font properties based on the LOGFONT
'UpdateProperties' : function () {
with (this) {
Height = LOGFONT.ReadDWORD(0);
Width = LOGFONT.ReadDWORD(4);
Escapement = LOGFONT.ReadDWORD(8);
Orientation = LOGFONT.ReadDWORD(12);
Weight = LOGFONT.ReadDWORD(16);
Italic = !!LOGFONT.GetAt(20);
Underline = !!LOGFONT.GetAt(21);
StrikeOut = !!LOGFONT.GetAt(22);
CharSet = LOGFONT.GetAt(23);
OutPrecision = LOGFONT.GetAt(24);
ClipPrecision = LOGFONT.GetAt(25);
Quality = LOGFONT.GetAt(26);
PitchAndFamily = LOGFONT.GetAt(27);
FaceName = LOGFONT.ReadString(28, true);
}
},
// Set the font of a control
'Set' : function (PlusWnd, ControlId) {
PlusWnd.SendControlMessage(ControlId, WM_SETFONT, this.HFONT, 0);
},
// Get the font of a control and update the LOGFONT, HFONT and font properties
'Get' : function (PlusWnd, ControlId) {
Interop.Call('gdi32.dll', 'GetObjectW', PlusWnd.SendControlMessage(ControlId, WM_GETFONT, 0, 0), this.LOGFONT.Size, this.LOGFONT.DataPtr);
this.UpdateHFONT();
this.UpdateProperties();
},
// Choose a font from a dialog box and update the LOGFONT, HFONT and font properties
'Choose' : function (Flags) {
this.CHOOSEFONT = Interop.Allocate(60);
this.CHOOSEFONT.WriteDWORD(0, this.CHOOSEFONT.Size);
this.CHOOSEFONT.WriteDWORD(12, this.LOGFONT.DataPtr);
this.CHOOSEFONT.WriteDWORD(20, Flags);
this.CHOOSEFONT.WriteDWORD(24, this.ColorRef);
var Height = this.LOGFONT.ReadDWORD(0);
if (!Height) this.LOGFONT.WriteDWORD(0, (10).toLogical() );
if (Interop.Call('comdlg32.dll', 'ChooseFontW', this.CHOOSEFONT.DataPtr) ) {
this.Height = this.CHOOSEFONT.ReadDWORD(16).toLogical() / 10;
this.ColorRef = this.CHOOSEFONT.ReadDWORD(24);
this.UpdateHFONT();
this.UpdateProperties();
} else this.LOGFONT.WriteDWORD(0, Height);
},
// Return the contents of the LOGFONT as a string
'Save' : function () {
var Cache = '';
for (var i = 0; i < 92; i++) Cache += this.LOGFONT.GetAt(i) + ' ';
return Cache;
},
// Load a string containing the contents of a LOGFONT and update the LOGFONT, HFONT and font properties
'Load' : function (Cache) {
Cache = Cache.split(' ');
for (var i = 0; i < 92; i++) this.LOGFONT.SetAt(i, Cache[i]);
this.UpdateHFONT();
this.UpdateProperties();
},
// Create a copy of this Font instance
'Clone' : function() {
return new Font(this);
}
}
// Convert point units(common font units) to logical units(used in the LOGFONT)
Number.prototype.toLogical = function () {
var hdc = Interop.Call('user32.dll', 'GetDC', null);
var LOGPIXELSY = 90;
LOGPIXELSY = Interop.Call('gdi32.dll', 'GetDeviceCaps', hdc, LOGPIXELSY);
Interop.Call('user32.dll', 'ReleaseDC', null, hdc);
return - Math.round( (this * LOGPIXELSY) / 72);
}
// Convert logical units(used in the LOGFONT) to point units(common font units)
Number.prototype.toPoint = function () {
var hdc = Interop.Call('user32.dll', 'GetDC', null);
var LOGPIXELSY = 90;
LOGPIXELSY = Interop.Call('gdi32.dll', 'GetDeviceCaps', hdc, LOGPIXELSY);
Interop.Call('user32.dll', 'ReleaseDC', null, hdc);
return - Math.round( (this * 72) / LOGPIXELSY);
}