# HG changeset patch # User sl # Date 1409592216 -7200 # Node ID fdda7642776af07fdf9751308535ad4930613160 # Parent f7ad2dce46a9b485261393138187f39330c2f014 Now displaying font width and height. diff -r f7ad2dce46a9 -r fdda7642776a Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Aug 31 21:34:58 2014 +0200 +++ b/Server/MainForm.Designer.cs Mon Sep 01 19:23:36 2014 +0200 @@ -43,6 +43,8 @@ this.buttonStartClient = new System.Windows.Forms.Button(); this.treeViewClients = new System.Windows.Forms.TreeView(); this.tabPageDisplay = new System.Windows.Forms.TabPage(); + this.buttonShowClock = new System.Windows.Forms.Button(); + this.buttonHideClock = new System.Windows.Forms.Button(); this.buttonPowerOff = new System.Windows.Forms.Button(); this.buttonPowerOn = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); @@ -72,8 +74,8 @@ this.buttonAddRow = new System.Windows.Forms.Button(); this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); - this.buttonHideClock = new System.Windows.Forms.Button(); - this.buttonShowClock = new System.Windows.Forms.Button(); + this.labelFontWidth = new System.Windows.Forms.Label(); + this.labelFontHeight = new System.Windows.Forms.Label(); this.panelDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -317,6 +319,26 @@ this.tabPageDisplay.Text = "Display"; this.tabPageDisplay.UseVisualStyleBackColor = true; // + // buttonShowClock + // + this.buttonShowClock.Location = new System.Drawing.Point(293, 124); + this.buttonShowClock.Name = "buttonShowClock"; + this.buttonShowClock.Size = new System.Drawing.Size(75, 23); + this.buttonShowClock.TabIndex = 23; + this.buttonShowClock.Text = "Show Clock"; + this.buttonShowClock.UseVisualStyleBackColor = true; + this.buttonShowClock.Click += new System.EventHandler(this.buttonShowClock_Click); + // + // buttonHideClock + // + this.buttonHideClock.Location = new System.Drawing.Point(293, 153); + this.buttonHideClock.Name = "buttonHideClock"; + this.buttonHideClock.Size = new System.Drawing.Size(75, 23); + this.buttonHideClock.TabIndex = 22; + this.buttonHideClock.Text = "Hide Clock"; + this.buttonHideClock.UseVisualStyleBackColor = true; + this.buttonHideClock.Click += new System.EventHandler(this.buttonHideClock_Click); + // // buttonPowerOff // this.buttonPowerOff.Location = new System.Drawing.Point(293, 211); @@ -626,13 +648,13 @@ this.marqueeLabelTop.AutoEllipsis = true; this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187); + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1); this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); this.marqueeLabelTop.Name = "marqueeLabelTop"; this.marqueeLabelTop.OwnTimer = false; this.marqueeLabelTop.PixelsPerSecond = 64; this.marqueeLabelTop.Separator = "|"; - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20); + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 9); this.marqueeLabelTop.TabIndex = 2; this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -642,7 +664,7 @@ // this.marqueeLabelBottom.AutoEllipsis = true; this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61); + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 21); this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); this.marqueeLabelBottom.Name = "marqueeLabelBottom"; this.marqueeLabelBottom.OwnTimer = false; @@ -654,31 +676,31 @@ this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.marqueeLabelBottom.UseCompatibleTextRendering = true; // - // buttonHideClock + // labelFontWidth // - this.buttonHideClock.Location = new System.Drawing.Point(293, 153); - this.buttonHideClock.Name = "buttonHideClock"; - this.buttonHideClock.Size = new System.Drawing.Size(75, 23); - this.buttonHideClock.TabIndex = 22; - this.buttonHideClock.Text = "Hide Clock"; - this.buttonHideClock.UseVisualStyleBackColor = true; - this.buttonHideClock.Click += new System.EventHandler(this.buttonHideClock_Click); + this.labelFontWidth.AutoSize = true; + this.labelFontWidth.Location = new System.Drawing.Point(13, 29); + this.labelFontWidth.Name = "labelFontWidth"; + this.labelFontWidth.Size = new System.Drawing.Size(56, 13); + this.labelFontWidth.TabIndex = 19; + this.labelFontWidth.Text = "Font width"; // - // buttonShowClock + // labelFontHeight // - this.buttonShowClock.Location = new System.Drawing.Point(293, 124); - this.buttonShowClock.Name = "buttonShowClock"; - this.buttonShowClock.Size = new System.Drawing.Size(75, 23); - this.buttonShowClock.TabIndex = 23; - this.buttonShowClock.Text = "Show Clock"; - this.buttonShowClock.UseVisualStyleBackColor = true; - this.buttonShowClock.Click += new System.EventHandler(this.buttonShowClock_Click); + this.labelFontHeight.AutoSize = true; + this.labelFontHeight.Location = new System.Drawing.Point(13, 46); + this.labelFontHeight.Name = "labelFontHeight"; + this.labelFontHeight.Size = new System.Drawing.Size(60, 13); + this.labelFontHeight.TabIndex = 20; + this.labelFontHeight.Text = "Font height"; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(624, 442); + this.Controls.Add(this.labelFontHeight); + this.Controls.Add(this.labelFontWidth); this.Controls.Add(this.labelWarning); this.Controls.Add(this.statusStrip); this.Controls.Add(this.tabControl); @@ -752,6 +774,8 @@ private System.Windows.Forms.Button buttonPowerOn; private System.Windows.Forms.Button buttonShowClock; private System.Windows.Forms.Button buttonHideClock; + private System.Windows.Forms.Label labelFontWidth; + private System.Windows.Forms.Label labelFontHeight; } } diff -r f7ad2dce46a9 -r fdda7642776a Server/MainForm.cs --- a/Server/MainForm.cs Sun Aug 31 21:34:58 2014 +0200 +++ b/Server/MainForm.cs Mon Sep 01 19:23:36 2014 +0200 @@ -41,9 +41,6 @@ InitializeComponent(); UpdateStatus(); - - // - tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); //We have a bug when drawing minimized and reusing our bitmap iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb); iCreateBitmap = false; @@ -53,11 +50,6 @@ { StartServer(); - // - CheckFontHeight(); - // - - if (Properties.Settings.Default.DisplayConnectOnStartup) { OpenDisplayConnection(); @@ -105,6 +97,20 @@ /// void CheckFontHeight() { + //Show font height and width + labelFontHeight.Text = "Font height: " + cds.Font.Height; + float charWidth = IsFixedWidth(cds.Font); + if (charWidth == 0.0f) + { + labelFontWidth.Visible = false; + } + else + { + labelFontWidth.Visible = true; + labelFontWidth.Text = "Font width: " + charWidth; + } + + //Now check font height and show a warning if needed. if (marqueeLabelBottom.Font.Height > marqueeLabelBottom.Height) { labelWarning.Text = "WARNING: Selected font is too height by " + (marqueeLabelBottom.Font.Height - marqueeLabelBottom.Height) + " pixels!"; @@ -342,13 +348,41 @@ } } + /// + /// Check if the given font has a fixed character pitch. + /// + /// + /// 0.0f if this is not a monospace font, otherwise returns the character width. + public float IsFixedWidth(Font ft) + { + Graphics g = CreateGraphics(); + char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' }; + float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width; + + bool fixedWidth = true; + + foreach (char c in charSizes) + if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth) + fixedWidth = false; + + if (fixedWidth) + { + return charWidth; + } + + return 0.0f; + } + private void UpdateStatus() { //Synchronize UI with settings //Load settings + + checkBoxShowBorders.Checked = cds.ShowBorders; + tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); marqueeLabelTop.Font = cds.Font; marqueeLabelBottom.Font = cds.Font; - checkBoxShowBorders.Checked = cds.ShowBorders; + CheckFontHeight(); checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; checkBoxReverseScreen.Checked = cds.ReverseScreen; comboBoxDisplayType.SelectedIndex = cds.DisplayType; @@ -689,7 +723,7 @@ client.Texts[j] = textField; } j++; - } + } //Only support two lines for now for (int i = 0; i < aTextFields.Count; i++) {