Now displaying font width and height.
1.1 --- a/Server/MainForm.Designer.cs Sun Aug 31 21:34:58 2014 +0200
1.2 +++ b/Server/MainForm.Designer.cs Mon Sep 01 19:23:36 2014 +0200
1.3 @@ -43,6 +43,8 @@
1.4 this.buttonStartClient = new System.Windows.Forms.Button();
1.5 this.treeViewClients = new System.Windows.Forms.TreeView();
1.6 this.tabPageDisplay = new System.Windows.Forms.TabPage();
1.7 + this.buttonShowClock = new System.Windows.Forms.Button();
1.8 + this.buttonHideClock = new System.Windows.Forms.Button();
1.9 this.buttonPowerOff = new System.Windows.Forms.Button();
1.10 this.buttonPowerOn = new System.Windows.Forms.Button();
1.11 this.label1 = new System.Windows.Forms.Label();
1.12 @@ -72,8 +74,8 @@
1.13 this.buttonAddRow = new System.Windows.Forms.Button();
1.14 this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel();
1.15 this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel();
1.16 - this.buttonHideClock = new System.Windows.Forms.Button();
1.17 - this.buttonShowClock = new System.Windows.Forms.Button();
1.18 + this.labelFontWidth = new System.Windows.Forms.Label();
1.19 + this.labelFontHeight = new System.Windows.Forms.Label();
1.20 this.panelDisplay.SuspendLayout();
1.21 this.tableLayoutPanel.SuspendLayout();
1.22 this.statusStrip.SuspendLayout();
1.23 @@ -317,6 +319,26 @@
1.24 this.tabPageDisplay.Text = "Display";
1.25 this.tabPageDisplay.UseVisualStyleBackColor = true;
1.26 //
1.27 + // buttonShowClock
1.28 + //
1.29 + this.buttonShowClock.Location = new System.Drawing.Point(293, 124);
1.30 + this.buttonShowClock.Name = "buttonShowClock";
1.31 + this.buttonShowClock.Size = new System.Drawing.Size(75, 23);
1.32 + this.buttonShowClock.TabIndex = 23;
1.33 + this.buttonShowClock.Text = "Show Clock";
1.34 + this.buttonShowClock.UseVisualStyleBackColor = true;
1.35 + this.buttonShowClock.Click += new System.EventHandler(this.buttonShowClock_Click);
1.36 + //
1.37 + // buttonHideClock
1.38 + //
1.39 + this.buttonHideClock.Location = new System.Drawing.Point(293, 153);
1.40 + this.buttonHideClock.Name = "buttonHideClock";
1.41 + this.buttonHideClock.Size = new System.Drawing.Size(75, 23);
1.42 + this.buttonHideClock.TabIndex = 22;
1.43 + this.buttonHideClock.Text = "Hide Clock";
1.44 + this.buttonHideClock.UseVisualStyleBackColor = true;
1.45 + this.buttonHideClock.Click += new System.EventHandler(this.buttonHideClock_Click);
1.46 + //
1.47 // buttonPowerOff
1.48 //
1.49 this.buttonPowerOff.Location = new System.Drawing.Point(293, 211);
1.50 @@ -626,13 +648,13 @@
1.51 this.marqueeLabelTop.AutoEllipsis = true;
1.52 this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent;
1.53 this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill;
1.54 - this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187);
1.55 + this.marqueeLabelTop.Location = new System.Drawing.Point(1, 1);
1.56 this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0);
1.57 this.marqueeLabelTop.Name = "marqueeLabelTop";
1.58 this.marqueeLabelTop.OwnTimer = false;
1.59 this.marqueeLabelTop.PixelsPerSecond = 64;
1.60 this.marqueeLabelTop.Separator = "|";
1.61 - this.marqueeLabelTop.Size = new System.Drawing.Size(254, 20);
1.62 + this.marqueeLabelTop.Size = new System.Drawing.Size(254, 9);
1.63 this.marqueeLabelTop.TabIndex = 2;
1.64 this.marqueeLabelTop.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
1.65 this.marqueeLabelTop.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.66 @@ -642,7 +664,7 @@
1.67 //
1.68 this.marqueeLabelBottom.AutoEllipsis = true;
1.69 this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill;
1.70 - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61);
1.71 + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, 21);
1.72 this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0);
1.73 this.marqueeLabelBottom.Name = "marqueeLabelBottom";
1.74 this.marqueeLabelBottom.OwnTimer = false;
1.75 @@ -654,31 +676,31 @@
1.76 this.marqueeLabelBottom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
1.77 this.marqueeLabelBottom.UseCompatibleTextRendering = true;
1.78 //
1.79 - // buttonHideClock
1.80 + // labelFontWidth
1.81 //
1.82 - this.buttonHideClock.Location = new System.Drawing.Point(293, 153);
1.83 - this.buttonHideClock.Name = "buttonHideClock";
1.84 - this.buttonHideClock.Size = new System.Drawing.Size(75, 23);
1.85 - this.buttonHideClock.TabIndex = 22;
1.86 - this.buttonHideClock.Text = "Hide Clock";
1.87 - this.buttonHideClock.UseVisualStyleBackColor = true;
1.88 - this.buttonHideClock.Click += new System.EventHandler(this.buttonHideClock_Click);
1.89 + this.labelFontWidth.AutoSize = true;
1.90 + this.labelFontWidth.Location = new System.Drawing.Point(13, 29);
1.91 + this.labelFontWidth.Name = "labelFontWidth";
1.92 + this.labelFontWidth.Size = new System.Drawing.Size(56, 13);
1.93 + this.labelFontWidth.TabIndex = 19;
1.94 + this.labelFontWidth.Text = "Font width";
1.95 //
1.96 - // buttonShowClock
1.97 + // labelFontHeight
1.98 //
1.99 - this.buttonShowClock.Location = new System.Drawing.Point(293, 124);
1.100 - this.buttonShowClock.Name = "buttonShowClock";
1.101 - this.buttonShowClock.Size = new System.Drawing.Size(75, 23);
1.102 - this.buttonShowClock.TabIndex = 23;
1.103 - this.buttonShowClock.Text = "Show Clock";
1.104 - this.buttonShowClock.UseVisualStyleBackColor = true;
1.105 - this.buttonShowClock.Click += new System.EventHandler(this.buttonShowClock_Click);
1.106 + this.labelFontHeight.AutoSize = true;
1.107 + this.labelFontHeight.Location = new System.Drawing.Point(13, 46);
1.108 + this.labelFontHeight.Name = "labelFontHeight";
1.109 + this.labelFontHeight.Size = new System.Drawing.Size(60, 13);
1.110 + this.labelFontHeight.TabIndex = 20;
1.111 + this.labelFontHeight.Text = "Font height";
1.112 //
1.113 // MainForm
1.114 //
1.115 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.116 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
1.117 this.ClientSize = new System.Drawing.Size(624, 442);
1.118 + this.Controls.Add(this.labelFontHeight);
1.119 + this.Controls.Add(this.labelFontWidth);
1.120 this.Controls.Add(this.labelWarning);
1.121 this.Controls.Add(this.statusStrip);
1.122 this.Controls.Add(this.tabControl);
1.123 @@ -752,6 +774,8 @@
1.124 private System.Windows.Forms.Button buttonPowerOn;
1.125 private System.Windows.Forms.Button buttonShowClock;
1.126 private System.Windows.Forms.Button buttonHideClock;
1.127 + private System.Windows.Forms.Label labelFontWidth;
1.128 + private System.Windows.Forms.Label labelFontHeight;
1.129 }
1.130 }
1.131
2.1 --- a/Server/MainForm.cs Sun Aug 31 21:34:58 2014 +0200
2.2 +++ b/Server/MainForm.cs Mon Sep 01 19:23:36 2014 +0200
2.3 @@ -41,9 +41,6 @@
2.4
2.5 InitializeComponent();
2.6 UpdateStatus();
2.7 -
2.8 - //
2.9 - tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
2.10 //We have a bug when drawing minimized and reusing our bitmap
2.11 iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
2.12 iCreateBitmap = false;
2.13 @@ -53,11 +50,6 @@
2.14 {
2.15 StartServer();
2.16
2.17 - //
2.18 - CheckFontHeight();
2.19 - //
2.20 -
2.21 -
2.22 if (Properties.Settings.Default.DisplayConnectOnStartup)
2.23 {
2.24 OpenDisplayConnection();
2.25 @@ -105,6 +97,20 @@
2.26 /// </summary>
2.27 void CheckFontHeight()
2.28 {
2.29 + //Show font height and width
2.30 + labelFontHeight.Text = "Font height: " + cds.Font.Height;
2.31 + float charWidth = IsFixedWidth(cds.Font);
2.32 + if (charWidth == 0.0f)
2.33 + {
2.34 + labelFontWidth.Visible = false;
2.35 + }
2.36 + else
2.37 + {
2.38 + labelFontWidth.Visible = true;
2.39 + labelFontWidth.Text = "Font width: " + charWidth;
2.40 + }
2.41 +
2.42 + //Now check font height and show a warning if needed.
2.43 if (marqueeLabelBottom.Font.Height > marqueeLabelBottom.Height)
2.44 {
2.45 labelWarning.Text = "WARNING: Selected font is too height by " + (marqueeLabelBottom.Font.Height - marqueeLabelBottom.Height) + " pixels!";
2.46 @@ -342,13 +348,41 @@
2.47 }
2.48 }
2.49
2.50 + /// <summary>
2.51 + /// Check if the given font has a fixed character pitch.
2.52 + /// </summary>
2.53 + /// <param name="ft"></param>
2.54 + /// <returns>0.0f if this is not a monospace font, otherwise returns the character width.</returns>
2.55 + public float IsFixedWidth(Font ft)
2.56 + {
2.57 + Graphics g = CreateGraphics();
2.58 + char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' };
2.59 + float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width;
2.60 +
2.61 + bool fixedWidth = true;
2.62 +
2.63 + foreach (char c in charSizes)
2.64 + if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth)
2.65 + fixedWidth = false;
2.66 +
2.67 + if (fixedWidth)
2.68 + {
2.69 + return charWidth;
2.70 + }
2.71 +
2.72 + return 0.0f;
2.73 + }
2.74 +
2.75 private void UpdateStatus()
2.76 {
2.77 //Synchronize UI with settings
2.78 //Load settings
2.79 +
2.80 + checkBoxShowBorders.Checked = cds.ShowBorders;
2.81 + tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
2.82 marqueeLabelTop.Font = cds.Font;
2.83 marqueeLabelBottom.Font = cds.Font;
2.84 - checkBoxShowBorders.Checked = cds.ShowBorders;
2.85 + CheckFontHeight();
2.86 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
2.87 checkBoxReverseScreen.Checked = cds.ReverseScreen;
2.88 comboBoxDisplayType.SelectedIndex = cds.DisplayType;
2.89 @@ -689,7 +723,7 @@
2.90 client.Texts[j] = textField;
2.91 }
2.92 j++;
2.93 - }
2.94 + }
2.95 //Only support two lines for now
2.96 for (int i = 0; i < aTextFields.Count; i++)
2.97 {