/// <summary> /// Return environment VS Font /// </summary> internal static Font GetVSFont(IServiceProvider serviceProvider) { Debug.Assert(serviceProvider != null, "Service Provider is null"); if (serviceProvider != null) { try { var hostLocale = serviceProvider.GetService(typeof(SUIHostLocale)) as IUIHostLocale2; if (hostLocale != null) { var fonts = new UIDLGLOGFONT[1]; var hr = hostLocale.GetDialogFont(fonts); ErrorHandler.ThrowOnFailure(hr); if (ErrorHandler.Succeeded(hr) && (fonts.Length > 0)) { return(FontFromUIDLGLOGFONT(fonts[0])); } } } catch (Exception e) { Debug.Fail(e.Message); throw; } } return(null); }
public void Font() { var fontSvc = Substitute.For<IUIHostLocale2>(); var logFont = new UIDLGLOGFONT[1]; logFont[0].lfItalic = 1; fontSvc.When(x => x.GetDialogFont(Arg.Any<UIDLGLOGFONT[]>())).Do(x => { var fontName = "Arial"; var lf = x.Args()[0] as UIDLGLOGFONT[]; lf[0].lfItalic = 1; lf[0].lfHeight = 16; lf[0].lfFaceName = new ushort[fontName.Length]; int i = 0; foreach (var ch in fontName) { lf[0].lfFaceName[i++] = (ushort)ch; } }); fontSvc.GetDialogFont(Arg.Any<UIDLGLOGFONT[]>()).Returns(VSConstants.S_OK); var appShell = Substitute.For<IApplicationShell>(); appShell.GetGlobalService<IUIHostLocale2>(typeof(SUIHostLocale)).Returns(fontSvc); var control = new SettingsPageControl(_csp, appShell, _fs); control.CreateControl(); control.Font.Italic.Should().BeTrue(); control.Font.Name.Should().Be("Arial"); }
public void Font() { var fontSvc = Substitute.For <IUIHostLocale2>(); var logFont = new UIDLGLOGFONT[1]; logFont[0].lfItalic = 1; fontSvc.When(x => x.GetDialogFont(Arg.Any <UIDLGLOGFONT[]>())).Do(x => { var fontName = "Arial"; var lf = x.Args()[0] as UIDLGLOGFONT[]; lf[0].lfItalic = 1; lf[0].lfHeight = 16; lf[0].lfFaceName = new ushort[fontName.Length]; int i = 0; foreach (var ch in fontName) { lf[0].lfFaceName[i++] = (ushort)ch; } }); fontSvc.GetDialogFont(Arg.Any <UIDLGLOGFONT[]>()).Returns(VSConstants.S_OK); var shell = Substitute.For <ICoreShell>(); shell.GetService <IUIHostLocale2>(typeof(SUIHostLocale)).Returns(fontSvc); var control = new SettingsPageControl(_csp, shell, _fs); control.CreateControl(); control.Font.Italic.Should().BeTrue(); control.Font.Name.Should().Be("Arial"); }
/// <summary> /// Return environment VS Font /// </summary> internal static Font GetVSFont(IServiceProvider serviceProvider) { Debug.Assert(serviceProvider != null, "Service Provider is null"); if (serviceProvider != null) { try { var hostLocale = serviceProvider.GetService(typeof(SUIHostLocale)) as IUIHostLocale2; if (hostLocale != null) { var fonts = new UIDLGLOGFONT[1]; var hr = hostLocale.GetDialogFont(fonts); ErrorHandler.ThrowOnFailure(hr); if (ErrorHandler.Succeeded(hr) && (fonts.Length > 0)) { return FontFromUIDLGLOGFONT(fonts[0]); } } } catch (Exception e) { Debug.Fail(e.Message); throw; } } return null; }
///<summary> /// Convert a UI Dialog Font to a System.Drawing.Font /// </summary> public static Font FontFromUiDialogFont(UIDLGLOGFONT logFont) { var conversion = new char[logFont.lfFaceName.Length]; for (int i = 0; i < logFont.lfFaceName.Length; i++) { conversion[i] = (char)logFont.lfFaceName[i]; } var familyName = new String(conversion); var emSize = Math.Abs(logFont.lfHeight); var style = FontStyle.Regular; int FW_NORMAL = 400; if (logFont.lfItalic > 0) { style |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { style |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { style |= FontStyle.Strikeout; } if (logFont.lfWeight > FW_NORMAL) { style |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var gdiCharSet = logFont.lfCharSet; var ff = new FontFamily(familyName); var teststyles = new FontStyle[5]; teststyles[0] = style; teststyles[1] = FontStyle.Regular; teststyles[2] = FontStyle.Bold; teststyles[3] = FontStyle.Italic; teststyles[4] = FontStyle.Bold | FontStyle.Italic; for (int i = 0; i < teststyles.Length; i++) { if (ff.IsStyleAvailable(teststyles[i])) { style = teststyles[i]; return(new Font(familyName, emSize, style, unit, gdiCharSet)); } } // We can't find a valid style for this font - fallback to just size and unit return(new Font(familyName, emSize, unit)); }
public static Font GetUiFont(this IApplicationShell appShell) { var fontSvc = appShell.GetGlobalService<IUIHostLocale2>(typeof(SUIHostLocale)); if (fontSvc != null) { var logFont = new UIDLGLOGFONT[1]; int hr = fontSvc.GetDialogFont(logFont); if (hr == VSConstants.S_OK && logFont[0].lfFaceName != null) { return IdeUtilities.FontFromUiDialogFont(logFont[0]); } } return null; }
Font GetVSFont() { IUIHostLocale hostLocale = _serviceProvider.GetService(typeof(IUIHostLocale)) as IUIHostLocale; if (hostLocale != null) { UIDLGLOGFONT[] dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); return(Font.FromLogFont(dlgFont[0])); } else { return(base.Font); } }
public static Font GetUiFont(this ICoreShell shell) { var fontSvc = shell.GetService <IUIHostLocale2>(typeof(SUIHostLocale)); if (fontSvc != null) { var logFont = new UIDLGLOGFONT[1]; int hr = fontSvc.GetDialogFont(logFont); if (hr == VSConstants.S_OK && logFont[0].lfFaceName != null) { return(IdeUtilities.FontFromUiDialogFont(logFont[0])); } } return(null); }
/// <summary> /// Gets the font provided by the VS environment for dialog UI. /// </summary> /// <returns>Dialog font, or null if it is not available.</returns> public static Font GetDialogFont() { IUIHostLocale uiHostLocale = WixHelperMethods.GetServiceNoThrow <IUIHostLocale, IUIHostLocale>(WixPackage.Instance); if (uiHostLocale != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (uiHostLocale.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(null); }
/// <summary> /// This is used to get the current dialog font for use in property pages, etc. /// </summary> /// <returns>The current dialog font or a Segoe UI 9pt font if it is not available</returns> public static Font GetDialogFont() { IUIHostLocale host = GetServiceFromPackage <IUIHostLocale, IUIHostLocale>(false); if (host != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (host.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(new Font("Segoe UI", 9.0f)); }
Font GetVSFont() { var hostLocale = ServiceProvider.GetService(typeof(IUIHostLocale)) as IUIHostLocale; if (hostLocale != null) { var dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); return(Font.FromLogFont(dlgFont[0])); } else { Debug.Fail("Failed to get IUIHostLocale service."); return(base.Font); } }
/// <summary> /// Gets the font provided by the VS environment for dialog UI. /// </summary> /// <returns>Dialog font, or null if it is not available.</returns> public static Font GetDialogFont() { IUIHostLocale uiHostLocale = XHelperMethods.GetServiceNoThrow <IUIHostLocale, IUIHostLocale>(AsyncProjectPackage.Instance); ThreadHelper.ThrowIfNotOnUIThread(); if (uiHostLocale != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (uiHostLocale.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(null); }
///<summary> /// Convert a UI Dialog Font to a System.Drawing.Font /// </summary> public static Font FontFromUiDialogFont(UIDLGLOGFONT logFont) { var conversion = new char[logFont.lfFaceName.Length]; for(int i = 0; i < logFont.lfFaceName.Length; i++) { conversion[i] = (char)logFont.lfFaceName[i]; } var familyName = new String(conversion); var emSize = Math.Abs(logFont.lfHeight); var style = FontStyle.Regular; int FW_NORMAL = 400; if (logFont.lfItalic > 0) { style |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { style |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { style |= FontStyle.Strikeout; } if (logFont.lfWeight > FW_NORMAL) { style |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var gdiCharSet = logFont.lfCharSet; var ff = new FontFamily(familyName); var teststyles = new FontStyle[5]; teststyles[0] = style; teststyles[1] = FontStyle.Regular; teststyles[2] = FontStyle.Bold; teststyles[3] = FontStyle.Italic; teststyles[4] = FontStyle.Bold | FontStyle.Italic; for (int i = 0; i < teststyles.Length; i++) { if (ff.IsStyleAvailable(teststyles[i])) { style = teststyles[i]; return new Font(familyName, emSize, style, unit, gdiCharSet); } } // We can't find a valid style for this font - fallback to just size and unit return new Font(familyName, emSize, unit); }
/// <summary> /// Convert UIDLGLOGFONT type to Font type. /// The code is copied over from env\vscore\package\CommonIDEStatics.cs /// </summary> /// <param name="logFont"></param> /// <returns></returns> private static Font FontFromUIDLGLOGFONT(UIDLGLOGFONT logFont) { var conversion = new char[logFont.lfFaceName.Length]; var i = 0; foreach (var convertChar in logFont.lfFaceName) { conversion[i++] = (char)convertChar; } var familyName = new String(conversion); Single emSize = 0 - logFont.lfHeight; var style = FontStyle.Regular; const int FW_NORMAL = 400; if (logFont.lfItalic > 0) { style |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { style |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { style |= FontStyle.Strikeout; } if (logFont.lfWeight > FW_NORMAL) { style |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var gdiCharSet = logFont.lfCharSet; return(new Font(familyName, emSize, style, unit, gdiCharSet)); }
/// <summary> /// Returns the current VS font from the provider /// </summary> /// <param name="provider">An IServiceProvider that contains IUIHostLocale</param> /// <returns>The current VS font</returns> internal static Font GetVsFont(IServiceProvider provider) { if (provider != null) { IUIHostLocale service = (IUIHostLocale)provider.GetService(typeof(IUIHostLocale)); UIDLGLOGFONT[] dlgFont = new UIDLGLOGFONT[1]; if (service != null && 0 == service.GetDialogFont(dlgFont)) { try { return(Font.FromLogFont(dlgFont[0])); } catch (ArgumentException) { // This can happen if a non-TrueType font is set as the system Icon font. // Eat the exception and use the system dialog font. } } } return(SystemFonts.DialogFont); }
private static Font FontFromUIDLGLOGFONT(UIDLGLOGFONT logFont) { var fonts = new char[logFont.lfFaceName.Length]; var num = 0; ushort[] lfFaceName = logFont.lfFaceName; foreach (ushort num2 in lfFaceName) { fonts[num++] = (char)num2; } var familyName = new string(fonts); var emSize = -logFont.lfHeight; var fontStyle = FontStyle.Regular; if (logFont.lfItalic > 0) { fontStyle |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { fontStyle |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { fontStyle |= FontStyle.Strikeout; } if (logFont.lfWeight > 400) { fontStyle |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var lfCharSet = logFont.lfCharSet; return(new Font(familyName, emSize, fontStyle, unit, lfCharSet)); }
public int GetDialogFont(UIDLGLOGFONT[] pLOGFONT) { pLOGFONT[0].lfFaceName = SystemFonts.CaptionFontFamily.Source.Select(c => (ushort)c).ToArray(); return 0; }
/// <summary> /// Convert UIDLGLOGFONT type to Font type. /// The code is copied over from env\vscore\package\CommonIDEStatics.cs /// </summary> /// <param name="logFont"></param> /// <returns></returns> private static Font FontFromUIDLGLOGFONT(UIDLGLOGFONT logFont) { var conversion = new char[logFont.lfFaceName.Length]; var i = 0; foreach (var convertChar in logFont.lfFaceName) { conversion[i++] = (char)convertChar; } var familyName = new String(conversion); Single emSize = 0 - logFont.lfHeight; var style = FontStyle.Regular; const int FW_NORMAL = 400; if (logFont.lfItalic > 0) { style |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { style |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { style |= FontStyle.Strikeout; } if (logFont.lfWeight > FW_NORMAL) { style |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var gdiCharSet = logFont.lfCharSet; return new Font(familyName, emSize, style, unit, gdiCharSet); }
public void Initialize() { if (Package.GetGlobalService(typeof(IUIHostLocale)) is IUIHostLocale hostLocale) { var dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); this.Font = Font.FromLogFont(dlgFont[0]); } // Form settings this.Name = Global.Form_Item_Name; this.Text = Global.Form_Item_Title; this.Icon = Global.Extension; // Tab settings this.tabProps.Text = Global.Form_PropertyTab_Title; this.tabAdv.Text = Global.Form_AdvancedTab_Title; // Framework lblFramework.Text = Global.Form_Framework; Dictionary <string, string> cboFrameworkSource = new Dictionary <string, string> { { "none", "none" }, { "react", "react" } }; cboFramework.DataSource = new BindingSource(cboFrameworkSource, null); cboFramework.DisplayMember = "Value"; cboFramework.ValueMember = "Key"; cboFramework.SelectedIndexChanged += Framework_SelectedIndexChanged; // Component Name lblComponentName.Text = Global.Form_ComponentName; txtComponentName.TextChanged += ComponentName_TextChanged; // Component Description lblComponentDescription.Text = Global.Form_ComponentDescription; txtComponentDescription.TextChanged += ComponentDescription_TextChanged; // Component Type lblComponentType.Text = Global.Form_ComponentType; Dictionary <string, string> cboComponentTypeSource = new Dictionary <string, string> { { "webpart", "webpart" }, { "extension", "extension" } }; cboComponentType.DataSource = new BindingSource(cboComponentTypeSource, null); cboComponentType.DisplayMember = "Value"; cboComponentType.ValueMember = "Key"; cboComponentType.SelectedIndexChanged += ComponentType_SelectedIndexChanged; // Extension type lblExtensionType.Visible = false; lblExtensionType.Text = Global.Form_ExtensionType; cboExtensionType.Visible = false; Dictionary <string, string> cboExtensionTypeSource = new Dictionary <string, string> { { "ApplicationCustomizer", "Application Customizer" }, { "FieldCustomizer", "Field Customizer" }, { "ListViewCommandSet", "List View CommandSet" } }; cboExtensionType.DataSource = new BindingSource(cboExtensionTypeSource, null); cboExtensionType.DisplayMember = "Value"; cboExtensionType.ValueMember = "Key"; cboExtensionType.SelectedIndexChanged += ExtensionType_SelectedIndexChanged; // Command string lblCommandString.Text = Global.Form_CommandString; lblCommandDescription.Text = Global.Form_AdvancedTab_CommandDescription; // Show window cbxShowWindow.Text = Global.Form_ShowCommandWindow; // buttons btnGenerate.Text = Global.Form_ButtonGenerate; btnGenerate.Enabled = commandValid; btnCancel.Text = Global.Form_ButtonCancel; // Footer lblFooter.Text = Global.Form_Footer_GeneratorText; // Set control visibility based on version //if (GeneratorVersion < Utility.gv1_1) //{ // lblExtensionType.Visible = false; // cboExtensionType.Visible = false; //} }
Font GetVSFont() { var hostLocale = ServiceProvider.GetService(typeof(IUIHostLocale)) as IUIHostLocale; if (hostLocale != null) { var dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); return Font.FromLogFont(dlgFont[0]); } else { Debug.Fail("Failed to get IUIHostLocale service."); return base.Font; } }
public void Initialize() { if (Package.GetGlobalService(typeof(IUIHostLocale)) is IUIHostLocale hostLocale) { var dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); this.Font = Font.FromLogFont(dlgFont[0]); } // Form settings this.Name = Global.Form_Project_Name; this.Text = Global.Form_Project_Title; this.Icon = Global.Extension; // Tab settings this.tabProps.Text = Global.Form_PropertyTab_Title; this.tabAdv.Text = Global.Form_AdvancedTab_Title; // Solution name lblSolutionName.Text = Global.Form_SolutionName; txtSolutionName.Enabled = false; txtSolutionName.TextChanged += SolutionName_TextChanged; // Framework lblFramework.Text = Global.Form_Framework; Dictionary <string, string> cboFrameworkSource = new Dictionary <string, string> { { "none", "none" }, { "react", "react" }, { "knockout", "knockout" } }; cboFramework.DataSource = new BindingSource(cboFrameworkSource, null); cboFramework.SelectedIndex = 0; cboFramework.DisplayMember = "Value"; cboFramework.ValueMember = "Key"; cboFramework.SelectedIndexChanged += Framework_SelectedIndexChanged; // Environment lblEnvironment.Text = Global.Form_Prompt_Environment_Label; Dictionary <string, string> cboEnvironmentSource = new Dictionary <string, string> { { "spo", Global.Form_Prompt_Environment_Option1 }, { "onprem", Global.Form_Prompt_Environment_Option2 }, { "onprem19", Global.Form_Prompt_Environment_Option3 } }; cboEnvironment.DataSource = new BindingSource(cboEnvironmentSource, null); cboEnvironment.SelectedIndex = 0; cboEnvironment.DisplayMember = "Value"; cboEnvironment.ValueMember = "Key"; cboEnvironment.SelectedIndexChanged += Environment_SelectedIndexChanged; // Component Name lblComponentName.Text = Global.Form_ComponentName; txtComponentName.TextChanged += ComponentName_TextChanged; // Component Description lblComponentDescription.Text = Global.Form_ComponentDescription; txtComponentDescription.TextChanged += ComponentDescription_TextChanged; // Component Type lblComponentType.Text = Global.Form_ComponentType; Dictionary <string, string> cboComponentTypeSource = new Dictionary <string, string> { { "webpart", Global.Form_Prompt_ComponentType_WebPart }, { "extension", Global.Form_Prompt_ComponentType_Extension } }; cboComponentType.DataSource = new BindingSource(cboComponentTypeSource, null); cboComponentType.SelectedIndex = 0; cboComponentType.DisplayMember = "Value"; cboComponentType.ValueMember = "Key"; cboComponentType.SelectedIndexChanged += ComponentType_SelectedIndexChanged; // Extension type lblExtensionType.Visible = false; lblExtensionType.Text = Global.Form_ExtensionType; cboExtensionType.Visible = false; Dictionary <string, string> cboExtensionTypeSource = new Dictionary <string, string> { { "ApplicationCustomizer", Global.Form_Prompt_ComponentType_Extension_1 }, { "FieldCustomizer", Global.Form_Prompt_ComponentType_Extension_2 }, { "ListViewCommandSet", Global.Form_Prompt_ComponentType_Extension_3 } }; cboExtensionType.DataSource = new BindingSource(cboExtensionTypeSource, null); cboExtensionType.DisplayMember = "Value"; cboExtensionType.ValueMember = "Key"; cboExtensionType.SelectedIndexChanged += ExtensionType_SelectedIndexChanged; // Package Manager lblPackageManager.Visible = true; lblPackageManager.Text = Global.Form_Prompt_PackageManager_Label; cboPackageManager.Visible = true; Dictionary <string, string> cboPackageManagerSource = new Dictionary <string, string> { { "npm", "NPM" }, { "pnpm", "PNPM" }, { "yarn", "Yarn" } }; cboPackageManager.DataSource = new BindingSource(cboPackageManagerSource, null); cboPackageManager.SelectedIndex = 0; cboPackageManager.DisplayMember = "Value"; cboPackageManager.ValueMember = "Key"; cboPackageManager.SelectedIndexChanged += cboPackageManager_SelectedIndexChanged; // Skip Feature Deployment cbxSkipFeatureDeployment.Text = Global.Form_Prompt_SkipFeature_Label; cbxSkipFeatureDeployment.Checked = false; cbxSkipFeatureDeployment.AutoSize = true; cbxSkipFeatureDeployment.CheckedChanged += SkipFeatureDeployment_CheckedChanged; // Skip NPM Install cbxSkipInstall.Text = Global.Form_Prompt_SkipInstall_Label; cbxSkipInstall.Checked = false; cbxSkipInstall.AutoSize = true; cbxSkipInstall.CheckedChanged += SkipInstall_CheckedChanged; //Domain Isolation cbxDomainIsolated.Text = Global.Form_Prompt_Domain_Isolated_Label; cbxDomainIsolated.Checked = false; cbxDomainIsolated.AutoSize = false; cbxDomainIsolated.CheckedChanged += cbxDomainIsolated_CheckedChanged; // Beta Features cbxPlusBeta.Text = Global.Form_Prompt_PlusBeta_Label; cbxPlusBeta.Checked = false; cbxPlusBeta.AutoSize = true; cbxSkipInstall.CheckedChanged += CbxSkipInstall_CheckedChanged; // Command string lblCommandString.Text = Global.Form_CommandString; lblCommandDescription.Text = Global.Form_AdvancedTab_CommandDescription; // Show window cbxShowWindow.Text = Global.Form_ShowCommandWindow; // buttons btnGenerate.Text = Global.Form_ButtonGenerate; btnGenerate.Enabled = commandValid; btnCancel.Text = Global.Form_ButtonCancel; // Footer lblFooter.Text = Global.Form_Footer_GeneratorText; }