// -------------------------- top of file FontAnalyzer.cs ------------------------- using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; public class MyForm : Form { public string statFontName = "MS ゴシック"; public float statFontSize = 36f; // === initial value !!! private MenuStrip mainMenu; public ToolStripMenuItem menu_Font, menu_Size; public Scroll scr; public TextBox textpower, textstr; ListBox listxy; string str = ""; float bx=0, by = 0; // --------------------------------------------- [System.STAThread] static void Main() { Application.Run(new MyForm()); } static public MyForm theMyForm; public MyForm() { int xbase = 500; this.ClientSize = new System.Drawing.Size(xbase+220, 580); this.Text="FontAnalyzer"; this.mainMenu = new MenuStrip(); this.Controls.Add(mainMenu); // ################## in MyForm2.cs ################## doMenuFontFamily(menu_Font = mainMenu.addItem("フォント(&N)")); doMenuFontSize(menu_Size = mainMenu.addItem("サイズ(&S)")); // ################################################### this.BackColor = Color.White; this.FormBorderStyle=FormBorderStyle.FixedToolWindow; // textstr = new TextBox(); textstr.SetBounds(xbase, 35, 40, 20); textstr.Font = new Font("MS ゴシック", 12); Controls.Add(textstr); scr = new Scroll(); scr.SetBounds(xbase+60, 35, 80, 20); scr.setview(0); scr.setwhole(19); Controls.Add(scr); textpower = new TextBox(); textpower.SetBounds(xbase+160, 35, 40, 20); textpower.Enabled = false; Controls.Add(textpower); listxy = new ListBox(); listxy.SetBounds(xbase, 70, 200, 500); listxy.MultiColumn = false; listxy.SelectedIndexChanged += (o, e) => { string strhere = listxy.SelectedItem.ToString(); int ix = strhere.IndexOf("X="), iy = strhere.IndexOf("Y="); int ex = strhere.IndexOf(",", ix), ey = strhere.IndexOf("}", iy); string sx = strhere.Substring(ix + 2, ex - ix - 2), sy = strhere.Substring(iy + 2, ey - iy - 2); bx = float.Parse(sx); by = float.Parse(sy); Invalidate(); }; Controls.Add(listxy); // ---------------------------------------------------- textstr.TextChanged += (o, e) => { redraw(); }; textstr.Text = "永"; scr.BaseChangedAnyway += (o, e) => { textpower.Text = (1+scr.getbase()).ToString(); power = float.Parse(textpower.Text); Invalidate(); }; scr.setbase(7); listxy.Select(); } // ======================================================================== void redraw() { str = textstr.Text; path = new GraphicsPath(); path.AddString(str, new FontFamily(statFontName), (int)FontStyle.Regular, statFontSize, new PointF(0f, 0f), StringFormat.GenericDefault); listxy.Items.Clear(); try{ for (int i=0; i { foreach (ToolStripMenuItem item1 in menu_Font.DropDownItems) { if (item1 != itemo) { item1.Checked = false; } } string str = ((ToolStripMenuItem)o).Text; statFontName = str; redraw(); }; } } // ================================================================ private void doMenuFontSize(ToolStripMenuItem menusizes) { float[] fs = new float[] { 8f, 10f, 12f, 16f, 20f, 28f, 36f, 48f, 64f, 96f, 192f}; foreach (float f in fs) { ToolStripMenuItem item = menusizes.addItem(f.ToString()); item.CheckOnClick= true; if (f == statFontSize) {item.Checked = true; } item.Click += (o, e) => { ToolStripMenuItem t = (ToolStripMenuItem)o; try{ ToolStripMenuItem u = (ToolStripMenuItem)menusizes.getItem(statFontSize.ToString()); if (t != u) { menusizes.getItem(statFontSize.ToString()).Checked= false; } } catch { } statFontSize = float.Parse(item.ToString()); redraw(); }; } } // ================================================================ protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.TranslateTransform(0, 100); for (int i=0, ibegin=0; i= 128) { PointF[] points = new PointF[i + 1 - ibegin]; for (int j=ibegin; j<=i; j++) { points[j - ibegin] = new PointF(power*path.PathPoints[j].X,power*path.PathPoints[j].Y); } g.DrawPolygon(Pens.Black, points); } } g.DrawLine(Pens.Red, power*bx - 90, power*by, power*bx + 90, power*by); g.DrawLine(Pens.Red, power*bx, power*by - 90, power*bx, power*by + 90); } // ======================================================== } // ############################################################################# public static class MenuExtention { // MenuStrip, ToolStripMenuItem 使うのに便利 // new public static ToolStripMenuItem addItem(this MenuStrip par, // new string str) { // new ToolStripMenuItem item=new ToolStripMenuItem(str); // new par.Items.Add(item); return item; } // new public static ToolStripMenuItem addItem(this MenuStrip par, // new string str, EventHandler handler) { // new ToolStripMenuItem item=new ToolStripMenuItem(str,null,handler); // new par.Items.Add(item); return item; } // new public static ToolStripMenuItem addItem(this ToolStripMenuItem par, // new string str, Image img, EventHandler handler) { // new ToolStripMenuItem item=new ToolStripMenuItem(str, img, handler); // new par.DropDownItems.Add(item); return item; } // new public static ToolStripMenuItem addItem(this ToolStripMenuItem par, // new string str, EventHandler handler) { // new ToolStripMenuItem item=new ToolStripMenuItem(str, null, handler); // new par.DropDownItems.Add(item); return item; } // new public static ToolStripMenuItem addItem( // new this ToolStripMenuItem par, string str) { // new ToolStripMenuItem item = new ToolStripMenuItem(str); // new par.DropDownItems.Add(item); return item; } // new public static void addItem( this ToolStripMenuItem par, ToolStripSeparator sepa) { // new par.DropDownItems.Add(sepa); } // new public static ToolStripMenuItem getItem(this ToolStripMenuItem par, // new string str) { // new foreach (object child in par.DropDownItems) { if (child is ToolStripMenuItem && ((ToolStripMenuItem)child).Text == str) { return (ToolStripMenuItem)child; } } return null; } // new // ====================================================================== public static ToolStripMenuItem getItem(this ToolStripMenuItem par, int ipage) { // new return (ToolStripMenuItem)(par.DropDownItems[ipage]); } // ====================================================================== public static MenuItem addItem(this MainMenu main, string str) { MenuItem son = new MenuItem(str); main.MenuItems.Add(son); return son; } // ==================================================================== public static MenuItem addItem(this MenuItem par, string str) { MenuItem son = new MenuItem(str); par.MenuItems.Add(son); return son; } // ==================================================================== public static MenuItem addItem(this MenuItem par, string str, EventHandler handler) { MenuItem son = new MenuItem(str, handler); par.MenuItems.Add(son); return son; } // ==================================================================== } // ############################################################################# public static class GraphicExtention { // MainMenu, MenuItem 使うのに便利 // old public static Graphics getGraphics(this Image img) { return Graphics.FromImage(img); } } // ############################################################################# public class Scroll : Panel {  public EventHandler BaseChangedAnyway, BaseChangedMechanical, BaseChangedByCode; protected void OnBaseChangedAnyway(object o, EventArgs i) { } // ==================================================================================== protected void OnBaseChangedMechanical(object o, EventArgs i) { } // ==================================================================================== protected void OnBaseChangedByCode(object o, EventArgs i) { } // ==================================================================================== protected override void OnSizeChanged(EventArgs e) { if (this.Width < 10) {this.Width=10; } if (this.Height < 10) {this.Height=10; } this._setwhkernel(); } // ==================================================================================== protected override void OnMove(EventArgs e) { base.OnMove(e); } // ==================================================================================== public Scroll() { this.BackColor = Color.FromArgb(255, 210, 210, 210); Controls.AddRange(new Control[]{ btfrom, btto, btM }); btfrom.BackColor = btto.BackColor = btM.BackColor = Color.White; BaseChangedAnyway += OnBaseChangedAnyway; BaseChangedMechanical += OnBaseChangedMechanical; BaseChangedByCode += OnBaseChangedByCode; this._setwhkernel(); this.btfrom.Click += (o,e)=>{ this.bas--; if (this.bas < 0) {this.bas=0; } this._setmechaFTG(); }; this.btto.Click+= (o, e)=>{ this.bas++; if (this.bas > this.whole-this.view) {this.bas=this.whole-this.view; } if (this.bas < 0) {this.bas=0; } this._setmechaFTG(); }; this.MouseDown += (o, e) => { int pv; if (this.Width > this.Height) {pv = e.X-Q; } else {pv = e.Y-Q; } // temporary if (this.inversef) {pv=this.pwhole-pv; } if (pv > this.pbase) { this.bas += this.largechange; if (this.bas > this.whole-this.view) {this.bas=this.whole-this.view; } } else { this.bas -= this.largechange; if (this.bas < 0) {this.bas=0; } } this._setmechaFTG(); }; this.btM.MouseDown += (o,edummy)=>{ Point e=MousePosition; int xy=e.X; if (this.Width < this.Height) {xy=e.Y; } if (this.inversef) { this.devipivot=-xy-this.pbase; } else { this.devipivot=xy-this.pbase; } this.dragging=true; }; this.btfrom.MouseMove += (o,e)=>{ screen(e); this._shift(e); }; this.btto.MouseMove += (o,e)=>{ screen(e); this._shift(e); }; this.MouseMove += (o,e) => { screen(e); this._shift(e); }; this.btM.MouseMove += (o,e)=>{ screen(e); this._shift(e); }; this.btM.MouseUp+= (o,e) => { this._shift(e); }; } // ==================================================================================== public void setbase(double itf) { bas=(int)Math.Floor(itf); this._setcode(); } // ==================================================================================== public int getbase() { return bas; } // ==================================================================================== public void setwhole(double itf) { whole=(int)(itf); _setcode(); } // ==================================================================================== public int getwhole() { return this.whole; } // ==================================================================================== public void setview(double itf) { this.view=(int)itf; this._setcode(); } // ==================================================================================== public int getview() { return this.view; } // ==================================================================================== public void setlargeChange(double itf) { this.largechange=(int)itf; } // ==================================================================================== public int getlargeChange() { return this.largechange; } // ==================================================================================== public void setinverse(bool f) { this.inversef=f; this._setM(); } // ==================================================================================== public bool getinverse() { return this.inversef; } // ==================================================================================== public void setx(int itf) { this.Location = new Point(itf, this.Location.Y); } // ==================================================================================== public void sety(int itf) { this.Location = new Point(this.Location.X, itf); } // ==================================================================================== public void setw(int itf) { this.setwh(itf, this.Height); } // ==================================================================================== public void seth(int itf) { this.setwh(this.Width, itf); } // ==================================================================================== // ###################################################################################### // ################################ public <---> private ################################ // ###################################################################################### private void setwh(int wtf, int htf) { this.Width=wtf; this.Height=htf; if (wtf < 15) {this.Width=15; } if (htf < 15) {this.Height=15; } this._setwhkernel(); } // ==================================================================================== private int Q, pwhole, pview; private int bas=0, whole=100, view=0, largechange=10, pbase=0; private bool inversef = false; private bool dragging=false; // , nn=typeof(xtf); private int devipivot=0; private Panel btfrom = new Panel(), btto = new Panel(); private Panel btM = new Panel(); private void screen(MouseEventArgs e) { if (e.Button == MouseButtons.None) { this.dragging=false; } } // ==================================================================================== private void _shift(MouseEventArgs edummy) { Point e=MousePosition; if (!this.dragging) { return; } var pv=e.X; if (this.Width < this.Height) {pv=e.Y; } if (this.inversef) { pv=-pv; } var devipivothere= pv-this.pbase; this.pbase += devipivothere-this.devipivot; if (this.pbase > this._proomtot()) {this.pbase=this._proomtot(); } if (this.pbase < 0) {this.pbase=0; } if (this._proomtot() == 0) { this.bas=0; } else { this.bas=this.pbase*(this.whole-this.view)/this._proomtot(); } BaseChangedMechanical(this, null); BaseChangedAnyway(this, null); this._setM(); } // ==================================================================================== private void _setmechaFTG() { if (this.whole-this.view == 0) { this.pbase=0; } else { this.pbase=this.bas*this._proomtot()/(this.whole-this.view); } BaseChangedMechanical(this, null); BaseChangedAnyway(this, null); this._setM(); } // ==================================================================================== private void _setwhkernel() { if (this.Width > this.Height) { this.Q=this.Height; this.pwhole=this.Width-this.Q-this.Q; Panel btL=this.btfrom, btR=this.btto; // temporary !!! if (this.inversef) { btR=this.btfrom; btL=this.btto; } btL.SetBounds(0, 0, Q-1, Q); btR.SetBounds(pwhole+Q, 0, Q-1, Q); btL.Paint += (o, e) => { Graphics g = e.Graphics; g.Clear(Color.White); Pen pen = new Pen(Color.Black); g.DrawLine(pen, this.Q / 4, this.Q / 2, this.Q / 2, this.Q * 3 / 4); g.DrawLine(pen, this.Q / 4, this.Q / 2, this.Q / 2, this.Q * 1 / 4); g.DrawRectangle(new Pen(Color.LightGray), 0,0,this.Width-1,this.Height-1); }; btR.Paint += (o, e) => { Graphics g = e.Graphics; g.Clear(Color.White); Pen pen = new Pen(Color.Black); g.DrawLine(pen, this.Q *3/ 4, this.Q / 2, this.Q / 2, this.Q * 3 / 4); g.DrawLine(pen, this.Q *3/ 4, this.Q / 2, this.Q / 2, this.Q * 1 / 4); g.DrawRectangle(new Pen(Color.LightGray), 0,0,this.Width-1,this.Height-1); }; } else { this.Q=this.Width; this.pwhole=this.Height-this.Q-this.Q; Panel btT=this.btfrom, btB=this.btto; // temporary !!! if (this.inversef) { btB=this.btfrom; btT=this.btto; } btT.SetBounds(0, 0, Q, Q-1); btB.SetBounds(0, pwhole+Q, Q, Q-1); btT.Paint += (o, e) => { Graphics g = e.Graphics; g.Clear(Color.White); Pen pen = new Pen(Color.Black); g.DrawLine(pen, this.Q / 4, this.Q / 2, this.Q / 2, this.Q / 4); g.DrawLine(pen, this.Q *3/ 4, this.Q / 2, this.Q / 2, this.Q / 4); g.DrawRectangle(new Pen(Color.LightGray), 0,0,this.Width-1,this.Height-1); }; btB.Paint += (o, e) => { Graphics g = e.Graphics; g.Clear(Color.White); Pen pen = new Pen(Color.Black); g.DrawLine(pen, this.Q / 4, this.Q / 2, this.Q / 2, this.Q *3/ 4); g.DrawLine(pen, this.Q *3/ 4, this.Q / 2, this.Q / 2, this.Q *3/ 4); g.DrawRectangle(new Pen(Color.LightGray), 0,0,this.Width-1,this.Height-1); }; } this._setcode(); } // ==================================================================================== private void _setcode() { if (this.bas > this.whole-this.view) {this.bas=this.whole-this.view; } if (this.bas < 0) {this.bas=0; } this.pview = this.pwhole * this.view / this.whole; if (this.pview < 15) {this.pview=15; } if (this.pview > this.pwhole) {this.pview = this.pwhole; } if (this.whole-this.view == 0) { this.pbase=0; } else { this.pbase=this.bas*this._proomtot()/(this.whole-this.view); } BaseChangedByCode(this, null); BaseChangedAnyway(this, null); this._setM(); } // ==================================================================================== private void _setM() { if (this.Width > this.Height) { if (this.inversef) { btM.SetBounds(pwhole + Q - pbase - pview, 0, pview, Q); } else { btM.SetBounds(Q + pbase, 0, pview, Q); } } else { if (this.inversef) { btM.SetBounds(0, pwhole + Q - pbase - pview, Q, pview); } else { btM.SetBounds(0, Q + pbase, Q, pview); } } btM.Paint += (o, e) => { Graphics g = e.Graphics; g.Clear(Color.White); Pen pen = new Pen(Color.LightGray); g.DrawRectangle(pen, 0,0,btM.Width-1,btM.Height-1); }; } // ==================================================================================== private int _proomtot() { int toret=this.pwhole-this.pview; if (toret < 0) {toret=0; } return toret; } // ==================================================================================== } // ######################################################################################## // ------------------------- bottom of file FontAnalyzer.cs -----------------------