// -------------------------- top of file FormMaker.cs(1.1) ------------------------- using System; using System.Text; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; using System.Drawing.Printing; public class MyForm : Form { public float EA = 0.96f; // 1pixel=(1/100)inch public int statwi, stathi; // A4 827 1169 public int intwi, inthi; // A4 827 1169 public void setpixel(float fval) { // 0.254 etc. EA= fval *96/ 25.4f; // means atom !!! float factor =0.254f / fval; intwi = (int)(statwi * factor); inthi = (int)(stathi * factor); hscr.setwhole(intwi); vscr.setwhole(inthi); } // ================================================================= // public Scroll vscr, hscr; // private MenuStrip mainMenu; public ToolStripMenuItem menu_File_Precise, menu_Printer, menu_Font, menu_Page, menu_Redraw; public Dictionary> psizes = new Dictionary>(); // --------------------------------------------- [System.STAThread] static void Main() { Application.Run(new MyForm()); } static public MyForm theMyForm; public Panel panel; public string printername = "", filename; public PrintDocument thePrinter; public MyDocument mydocument; Graphics panelgraphics; public MyForm() { theMyForm = this; thePrinter = new PrintDocument(); thePrinter.PrinterSettings = new PrinterSettings(); thePrinter.PrintController = new StandardPrintController(); this.Text="FormMaker"; panel = new Panel(); hscr = new Scroll(); vscr = new Scroll(); this.ClientSize = new System.Drawing.Size(880, 1180); this.mainMenu = new MenuStrip(); this.Controls.Add(mainMenu); // ################## in MyForm2.cs ################## doMenuFile(mainMenu.addItem("ファイル(&F)")); doMenuPrinter(menu_Printer=mainMenu.addItem("プリンタと紙サイズ(&R)")); doMenuPage(menu_Page = mainMenu.addItem("ページ(&P)")); doMenuOut(mainMenu.addItem("ページ画像ファイル出力")); doMenuPageSize(mainMenu.addItem("ページサイズ(名前がコピーされる)")); doMenuFontFamily(menu_Font = mainMenu.addItem("フォント(選ぶと名前がコピーされる)")); menu_Redraw = mainMenu.addItem("再描画"); menu_Redraw.Click += (o, e) => { this.myrefreshmaster(false); }; // ################################################### Controls.Add(hscr); Controls.Add(vscr); hscr.BaseChangedMechanical += this.myrefresh3; vscr.BaseChangedMechanical += this.myrefresh3; this.Controls.Add(panel); } // ======================================================================= protected override void OnSizeChanged(System.EventArgs e) { this.Refresh(); int ww = this.ClientSize.Width-1, hh = this.ClientSize.Height-1, t = 20, x=2, y=25, hview = ww-t-x, vview=hh-t-y; panel.SetBounds(x,y,hview,vview); // panel: Panel 30 50 hscr.SetBounds(x, hh-t, hview, t); hscr.setview(hview); vscr.SetBounds(ww - t, y, t, vview); vscr.setview(vview); myrefreshmaster(false); } // ========================================================================== public int minimulwidth=0, minimulheight=0; // of ClientSize !!! public string filenameactive=""; PaperSize _papersize = null; // new PaperSize("A4", 827, 1169); // null; public PaperSize PPSZCIz{ // present paper size (in centi inch) get{ return _papersize; } set{ _papersize = value; } } // ========================================================================== Dictionary settingOfPrinter = new Dictionary(); Dictionary parOfPaper = new Dictionary(); Dictionary psOfPaper = new Dictionary(); private void doMenuFile(ToolStripMenuItem menu) { menu.addItem("開く(&O)", (o, e) => { // open(o, e); string strlenstate = ""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.FileName = filename; openFileDialog1.Filter = "formmaker files (*.fmm)|*.fmm|text files (*.txt)|*.txt|all files (*.*)|*.*"; // = "All files (*.*)|*.*|mln files (*.mln)|*.mln|txt files (*.txt)|*.txt"; openFileDialog1.FilterIndex = 1; // === 1.. !!! openFileDialog1.RestoreDirectory = true; // System.Windows.Forms.OpenFileDialog; System.Windows.Forms.DialogResult result = openFileDialog1.ShowDialog(); // === dialog works here !!! if (result != DialogResult.OK) { return; } filename=openFileDialog1.FileName; System.IO.FileStream fs=new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); System.IO.StreamReader sr=new System.IO.StreamReader(fs, Encoding.UTF8); strlenstate=sr.ReadToEnd(); fs.Close(); strs = new List(); for (int i=0; i= 0) { strsize=knowfirstparam(str, i); break; } } stathi=psizes[strsize].Item1; statwi = psizes[strsize].Item2; mydocument = new MyDocument(strs); dicimage=new Dictionary(); menu_Page.clear(); setpixel(mydocument.getvalue("25.4 /100")); foreach (string str in strs) { int j=str.IndexOf("["); if (j >= 0 && str.Length >= j+5 && str.Substring(j,5) == "[End]") { break; } int i = str.IndexOf("[Page]"); if (i >= 0) { string pnumb=knowfirstparam(str, i); dicimage.Add(pnumb, null); ToolStripMenuItem mnu=menu_Page.addItem(pnumb); mnu.CheckOnClick = true; mnu.Click += (oo, ee) => { pagenowcheck.Checked = false; ((ToolStripMenuItem)oo).Checked = true; pagenowcheck = (ToolStripMenuItem)oo; myrefreshmaster(false); }; } int k = str.IndexOf("[mm/px]"); if (k >= 0) { int l = str.IndexOf("//",k+7); if (l<0) { l = str.Length; } string strval = str.Substring(k + 7, l - k - 7).Trim(); float fval = mydocument.getvalue(strval); setpixel(fval); } } if (menu_Page.DropDownItems.Count == 0) { ToolStripMenuItem theitem=menu_Page.addItem("default"); dicimage.Add(theitem.Text, null); theitem.Checked = true; } pagenowcheck = (ToolStripMenuItem)menu_Page.DropDownItems[0]; pagenowcheck.Checked= true; myrefreshmaster(false); }); menu_File_Precise=menu.addItem("紙サイズの詳細表示"); // ========================== menu_File_Precise.CheckOnClick = true; menu_File_Precise.CheckedChanged += (o, e) => { Cursor = Cursors.WaitCursor; foreach (ToolStripMenuItem menuprinter in menu_Printer.DropDownItems) { PrinterSettings settingshere=settingOfPrinter[menuprinter]; string pname = settingshere.PrinterName; printername = pname; PrinterSettings.PaperSizeCollection col= settingshere.PaperSizes; foreach (ToolStripMenuItem grandsonhere in menuprinter.DropDownItems) { PaperSize papersizehere = psOfPaper[grandsonhere]; if (menu_File_Precise.Checked) { grandsonhere.Text = papersizehere.ToString(); } else { grandsonhere.Text = papersizehere.PaperName; } } } Cursor = Cursors.Default; }; // ----------------------------------------------------------- string pagefirstprint, pagefinaltoprint=""; List pagestoprint=null; menu.addItem("印刷", null, (o,e)=>{ // begin printing pages !!! if (pagesstat == null) { System.Windows.Forms.MessageBox.Show("no page !"); return; } thePrinter.PrinterSettings.PrinterName = printername; // "Adobe PDF" thePrinter.DefaultPageSettings.PaperSize = PPSZCIz; // thePrinter.DefaultPageSettings.Landscape = false; // string strppr = PPSZCIz.ToString(); DialogBoxPages pages = new DialogBoxPages(this); DialogResult result=pages.ShowDialog(); if (result != DialogResult.OK) { return; } pagefirstprint = pages.cbfirst.Text; pagefinaltoprint = pages.cblast.Text; pagestoprint = new List(); bool selecting = false; foreach(ToolStripMenuItem mn in menu_Page.DropDownItems) { if (mn.Text == pagefirstprint) { selecting = true; } if (selecting) { pagestoprint.Add(mn.Text); } if (mn.Text == pagefinaltoprint) { selecting = false; } } thePrinter.Print(); } ); // === thePrintDocument.PrintPage(next event) is invoked !!! thePrinter.PrintPage += (object o, PrintPageEventArgs eofeachpage) => { // print page !!! List pagestoprinthere = pagestoprint; Graphics gofeachpage = eofeachpage.Graphics; // === Graphic context to print !!! toprintpage(gofeachpage, pagestoprint[0]); if (pagestoprint.Count == 1) { eofeachpage.HasMorePages = false; } else { pagestoprint.RemoveAt(0); eofeachpage.HasMorePages = true; } }; menu.addItem(new ToolStripSeparator()); menu.addItem("csvから変換", (o, e) => { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "formmaker files (*.csv)|*.csv|text files (*.txt)|*.txt|all files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; // === 1.. !!! openFileDialog1.RestoreDirectory = true; // System.Windows.Forms.OpenFileDialog; DialogResult result = openFileDialog1.ShowDialog(); // === dialog works here !!! if (result != DialogResult.OK) { return; } string filenamehere=openFileDialog1.FileName; System.IO.FileStream fs=new System.IO.FileStream(filenamehere, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None); System.IO.StreamReader sr=new System.IO.StreamReader(fs, Encoding.Default); // UTF8 string strtop=sr.ReadLine(); List strstop = parseline(strtop); int iname = 0, ipost = 0, iaddr1 = 0, iaddr2 = 0; string strtoout = "[PSize]ハガキ\r\n"; strtoout += "[mm/px]25.4 /100\r\n"; strtoout += "#W=1, #N=1, #E=400, #S=596\r\n"; strtoout += "AX=159,AY=40,AP=27.3,FP=22,FA=14,FN=24,xA=30,yA=210,xA2=50,yA2=234,xN=60,yN=270\r\n\r\n"; for(int i=0; i strsline = parseline(strline); string strname = strsline[iname], strpostpre = strsline[ipost], straddr1 = strsline[iaddr1], straddr2 = ""; string strpost = strpostpre.Substring(0, 3) + strpostpre.Substring(4); string strpage=knowfirstparam(strname, 0); int j = strname.IndexOf(","); List subs = new List(); if (j >= 0) { string strrem = strname.Substring(j + 1); strname = strname.Substring(0, j); for (; ;) { int k = strrem.IndexOf(","); if (k < 0) { k = strrem.Length; } subs.Add(strrem.Substring(0, k)); if (k >= strrem.Length) { break; } strrem = strrem.Substring(k + 1); } } if (strsline.Count>iaddr2) { straddr2 = strsline[iaddr2]; } strtoout += "[Page]"+strpage+"家\r\n"; strtoout += "[Font]HG丸ゴシックM-PRO,FP\r\n[DSingle]AX,AY,AP;"; strtoout += strpost + "\r\n[Font]FA\r\n[DSingle]xA, yA;"+straddr1+"\r\n"; strtoout += "[DSingle]xA2, yA2;"+straddr2 + "\r\n"; strtoout += "[Font]FN\r\n[DSingle]xN, yN;" + strname + " 様\r\n"; foreach (string str in subs) { strtoout += "[DSingle]xN 98, #U 4;" + str + " 様\r\n"; } strtoout += "\r\n"; } sr.Close(); fs.Close(); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); string simplename=System.IO.Path.GetFileNameWithoutExtension(filenamehere); ; saveFileDialog1.FileName = simplename; saveFileDialog1.Filter = "FormMaker files (*.fmm)|*.fmm|txt files (*.txt)|*.txt|all files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; // === 1.. !!! saveFileDialog1.RestoreDirectory = true; // System.Windows.Forms.OpenFileDialog; System.Windows.Forms.DialogResult result2 = saveFileDialog1.ShowDialog(); // === dialog works here !!! if (result2 != DialogResult.OK) { return; } filename=saveFileDialog1.FileName; System.IO.FileStream fs2=new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None); System.IO.StreamWriter sw=new System.IO.StreamWriter(fs2, Encoding.UTF8); sw.Write(strtoout); sw.Flush(); sw.Close(); fs.Close(); }); menu.addItem("終了(&E)", (o,e)=>{ Dispose(true); }); /* menu.addItem("save", (o,e)=>{ // === to save *.js !!! SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.FileName = filename; saveFileDialog1.Filter = "javascript files (*.js)|*.js|all files (*.*)|*.*"; // = "All files (*.*)|*.*|mln files (*.mln)|*.mln|txt files (*.txt)|*.txt"; saveFileDialog1.FilterIndex = 1; // === 1.. !!! saveFileDialog1.RestoreDirectory = true; // System.Windows.Forms.OpenFileDialog; System.Windows.Forms.DialogResult result = saveFileDialog1.ShowDialog(); // === dialog works here !!! if (result != DialogResult.OK) { return; } filename=saveFileDialog1.FileName; System.IO.FileStream fs=new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None); System.IO.StreamWriter sw=new System.IO.StreamWriter(fs, Encoding.UTF8); foreach(string str in strs) { string strret = "strsprog.push(\"" + str + "\")"; sw.WriteLine(strret); } sw.Flush(); fs.Close(); }); */ } // ================================================================ List parseline(string strline) { List strs = new List(); int i = 0; for ( ; ; ) { int ib = strline.IndexOf("\"", i), ic = strline.IndexOf(",", i); if (ic < 0) { ic = strline.Length; } if (ib >= 0 && ib < ic) { int ibb = strline.IndexOf("\"", ib + 1); int icc = strline.IndexOf(",", ibb + 1); if (icc < 0) { icc = strline.Length; } ic = icc; strs.Add(strline.Substring(ib + 1, ibb - ib - 1)); } else { strs.Add(strline.Substring(i, ic - i)); } i = ic+1; if (i > strline.Length) { break; } } return strs; } // ================================================================ private void doMenuPrinter(ToolStripMenuItem menu) { foreach (string printernamehere in PrinterSettings.InstalledPrinters) { ToolStripMenuItem itemeachprinter=menu.addItem(printernamehere); PrinterSettings printerhere=new PrinterSettings(); printerhere.PrinterName = printernamehere; settingOfPrinter.Add(itemeachprinter, printerhere); PrinterSettings.PaperSizeCollection col= printerhere.PaperSizes; foreach (PaperSize size in col) { string strwhole = size.ToString(), strtitle = size.PaperName; // strref = "A4"; ToolStripMenuItem grandsonhere=itemeachprinter.addItem(strtitle); grandsonhere.CheckOnClick = true; if (menu_File_Precise.Checked) { strtitle = strwhole; } parOfPaper.Add(grandsonhere, itemeachprinter); psOfPaper.Add(grandsonhere, size); grandsonhere.Click += (o, e) => { Grandsonhere_Setmple(o); }; // --------------------------------------------- if (strtitle == "A4") { grandsonhere.Checked = true; Grandsonhere_Setmple(grandsonhere); } } } } // ================================================================ private void Eachprinter_Click(object sender, EventArgs e) { ToolStripMenuItem eachprinterclicked = (ToolStripMenuItem)sender; string printernamehere = eachprinterclicked.Text; printername = eachprinterclicked.Text; foreach (ToolStripMenuItem mprinter in menu_Printer.DropDownItems) { if (mprinter != eachprinterclicked ) { mprinter.Checked = false; } } foreach (ToolStripMenuItem gson in eachprinterclicked.DropDownItems) { if (gson.Checked) { PPSZCIz = psOfPaper[gson]; break; } } } // =============================================================== ToolStripMenuItem grandsonselected; public void Grandsonhere_Setmple(object sender) { if (sender != null) { grandsonselected = (ToolStripMenuItem)sender; } PPSZCIz = psOfPaper[grandsonselected]; ToolStripMenuItem menuprinter = parOfPaper[grandsonselected]; foreach (ToolStripMenuItem gson in menuprinter.DropDownItems) { if (gson != grandsonselected) { gson.Checked = false; } } grandsonselected.Checked = true; Eachprinter_Click(menuprinter, null); menuprinter.Checked = true; } // ======================================== private void doMenuOut(ToolStripMenuItem menu) { menu.Click += (o, e) => { if (mydocument == null) { MessageBox.Show("No document is registered !!! "); return; } Image bm = dicimage[pagenowcheck.Text]; FileDialog fd = new SaveFileDialog(); string strfilter = "PNG files|*.png|JPEG files|*.jpg|GIF files|*.gif|TIFF files|*.tif|Bitmaps|*.bmp"; fd.Filter = strfilter; DialogResult dr = fd.ShowDialog(); if (dr == DialogResult.OK) { string strfile = fd.FileName; int find = fd.FilterIndex; if(find == 1) { bm.Save(strfile,System.Drawing.Imaging.ImageFormat.Png); } else if (find == 2) { bm.Save(strfile,System.Drawing.Imaging.ImageFormat.Jpeg); } else if (find == 3) { bm.Save(strfile,System.Drawing.Imaging.ImageFormat.Gif); } else if (find == 4) { bm.Save(strfile,System.Drawing.Imaging.ImageFormat.Tiff); } else if (find == 5) { bm.Save(strfile,System.Drawing.Imaging.ImageFormat.Bmp); } } }; } // ================================================================ private void doMenuPageSize(ToolStripMenuItem menu) { doMenuPageSize_adddic(menu, "A3", 1654, 1169); doMenuPageSize_adddic(menu, "A4", 1169, 827); doMenuPageSize_adddic(menu, "A5", 827, 583); doMenuPageSize_adddic(menu, "B4", 1433, 1012); doMenuPageSize_adddic(menu, "B5", 1012, 717); doMenuPageSize_adddic(menu, "B6", 717, 504); doMenuPageSize_adddic(menu, "ハガキ", 586, 394); doMenuPageSize_adddic(menu, "長3", 925, 472); doMenuPageSize_adddic(menu, "長4", 807, 354); doMenuPageSize_adddic(menu, "角3", 1091, 850); doMenuPageSize_adddic(menu, "Letter", 1100, 850); doMenuPageSize_adddic(menu, "Tabloid", 1700, 1100); doMenuPageSize_adddic(menu, "Legal", 1400, 850); doMenuPageSize_adddic(menu, "Executive", 1050, 725);   } // ================================================================ void doMenuPageSize_adddic(ToolStripMenuItem menu, string str, int h, int w) { psizes.Add(str, new Tuple(h, w)); menu.addItem(str).Click += (o, e) => { Clipboard.SetText(o.ToString()); }; } // ================================================================ private void doMenuFontFamily(ToolStripMenuItem menu) { System.Drawing.Text.InstalledFontCollection ifc = new System.Drawing.Text.InstalledFontCollection(); FontFamily[] ffs = ifc.Families; foreach (FontFamily ff in ffs) { if (ff.Name == "MS ゴシック") { menu.addItem(ff.Name); break; } } foreach (FontFamily ff in ffs) { if (ff.Name == "MS 明朝") { menu.addItem(ff.Name); break; } } foreach (FontFamily ff in ffs) { if (ff.IsStyleAvailable(FontStyle.Regular)) { if (ff.Name != "MS ゴシック" && ff.Name != "MS 明朝") { menu.addItem(ff.Name); } } } foreach (ToolStripMenuItem submenu in menu.DropDownItems) { submenu.Click += (o, e) => { string str = o.ToString(); Clipboard.SetText(str); }; } } // ================================================================ private void doMenuPage(ToolStripMenuItem menupages) { ToolStripMenuItem theitem=menu_Page.addItem("default"); pagenowcheck=theitem; dicimage = new Dictionary(); dicimage[pagenowcheck.Text] = null; } // ============================================================= List strs; Dictionary dicimage; // public void myrefreshmaster(bool force) { // === prepare background in display !!! if (mydocument == null) { return; } /* int ww = this.ClientSize.Width, hh = this.ClientSize.Height; int hview = ww-30, vview=hh-50; if (hview > intwi) { hview = intwi; hscr.setbase(0); } if (vview > inthi) { vview = inthi; vscr.setbase(0); } hscr.setwhole(intwi); hscr.setview(hview); vscr.setwhole(inthi); vscr.setview(vview); */ string strpg = pagenowcheck.Text; if (dicimage[pagenowcheck.Text] == null || force) { Cursor = Cursors.WaitCursor; Image bmpage = new Bitmap(intwi, inthi); Graphics g = bmpage.getGraphics(); g.FillRectangle(new SolidBrush(Color.White), 0,0, intwi, inthi); mydocument.paintpage(g, pagenowcheck.Text); dicimage[pagenowcheck.Text] = bmpage; Cursor = Cursors.Default; } myrefresh3(null, null); Invalidate(); hscr.Refresh(); } // ========================================================================= public void myrefresh3(object o, EventArgs e) { if (dicimage[pagenowcheck.Text] == null) { return; } panel.BackColor = Color.LightGray; panel.Refresh(); panelgraphics = panel.CreateGraphics(); panelgraphics.DrawImage(dicimage[pagenowcheck.Text], -hscr.getbase(), -vscr.getbase(), intwi, inthi); } // ========================================================================= void toprintpage(Graphics gg, string pagename) { gg.ScaleTransform(EA, EA); if (dicimage[pagename] == null) { Image bmpage = new Bitmap(intwi, inthi); Graphics g = bmpage.getGraphics(); g.FillRectangle(new SolidBrush(Color.White), 0,0, intwi, inthi); mydocument.paintpage(g, pagename); dicimage[pagename] = bmpage; } gg.DrawImage(dicimage[pagename], 0,0); } // ========================================================================= string knowfirstparam(string str, int ibbegin) { int i = str.IndexOf("]", ibbegin); string trstr = str.Substring(i+1).Trim(); int j1=trstr.IndexOf(" "), j2=trstr.IndexOf("/"); if (j1 < 0) {j1 = trstr.Length; } if (j2 >= 0 && j1 > j2) { j1 = j2; } string strparam=trstr.Substring(0, j1); return strparam; } // ========================================================================= ToolStripMenuItem pagenowcheck = null; string trim(string a) { if (a.Length >= 2 && a.Substring(a.Length-2, 2) == "\r\n") { a = a.Substring(0, a.Length - 2); } if (a.Length >= 2 && a.Substring(0, 2) == "\r\n") { a = a.Substring(a.Length - 2); } return a; } // =============================================================== public int selectedpagestat = 1; public string nselectedpagestat = "1"; public List> pagesstat=new List>(); } // ############################################################################# public class DialogBoxPages : System.Windows.Forms.Form { public ComboBox cbfirst, cblast; // public DialogBoxPages(MyForm partf) { { Label label = new Label(); label.SetBounds(30, 32, 80, 16); label.Text = "開始ページ"; Controls.Add(label); cbfirst = new ComboBox(); cbfirst.SetBounds(120, 32, 100, 16); } { Label label = new Label(); label.SetBounds(30, 62, 80, 16); label.Text = "終了ページ"; Controls.Add(label); cblast = new ComboBox(); cblast.SetBounds(120, 62, 100, 16); } foreach(ToolStripMenuItem o in partf.menu_Page.DropDownItems) { string nm = o.Text; cbfirst.Items.Add(nm); cblast.Items.Add(nm); } cbfirst.SelectedIndex = 0; cblast.SelectedIndex = cblast.Items.Count-1; { Button button = new Button(); button.Location = new System.Drawing.Point(30, 92);  button.Text = "OK"; button.DialogResult = System.Windows.Forms.DialogResult.OK; Controls.Add(button); } { Button button = new Button(); button.Location = new System.Drawing.Point(190, 92);  button.Text = "Cancel"; button.DialogResult = System.Windows.Forms.DialogResult.Cancel; Controls.Add(button); } this.ClientSize = new System.Drawing.Size(320, 129); this.Controls.AddRange(new System.Windows.Forms.Control[] { cbfirst, cblast }); this.Text = "印刷ページ範囲";   this.MinimizeBox=this.MaximizeBox=false; } // === as a dialog box !!! } // ################################################################################### 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 ToolStripMenuItem clear( // new this ToolStripMenuItem par) { // new par.DropDownItems.Clear(); return par; } // 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; } // ==================================================================================== } // ######################################################################################## public class MyDocument { Dictionary _istr; Pen globalpen; public float globalfontsize=12; Brush globaltextbrush=new SolidBrush(Color.Black); // === default for string !!! Graphics globalg; public string globalstr = ""; public string globalfontfamily = "MS ゴシック"; float ydumper = 10; public List strs; List beginbrackets, iters; public string Page; public MyDocument(List strstf) { strs = strstf; } // ========================================================================== public bool paintpage(Graphics g, string Pagetf) { // === design and print !!! finalf // === in this world, 1pixel == 0.254mm !!! Page = Pagetf; globalg = g; globalpen = new Pen(Color.Black, 1); _istr = new Dictionary(); // Let("#T=1, #R=0, #H=0, #U=0, #E=0, #W=0, #N=0, #S=0"); beginbrackets = new List(); iters = new List(); int ilim = 10000; if (ilim > strs.Count) { ilim = strs.Count; } bool active = true; for (int i=0; i= 0) { strline = strwholeline.Substring(0, th); } int c = strline.IndexOf("["); int d = strline.IndexOf("]"); if (strline.Trim() == "") { continue; } if(c < 0) { if(active) { Let(strline); } continue; } string strpre = strline.Substring(0, c).Trim(); string strcommand = strline.Substring(c + 1, d - c - 1); string strrestwild = strwholeline.Substring(d + 1); string strrestnontrim = strline.Substring(d + 1); string strresttrimmed = getessencetrim(strrestwild); if (strcommand == "PSize") { continue; } else if (strcommand == "Page") { if (strresttrimmed == Page) { active = true; } else { active = false; } continue; } else if (strcommand == "End") { active = true; break; } if (!active) { continue; } if (strpre != "") { Let(strpre); } switch (strcommand) { case "Iter": { Iter(strresttrimmed, i); break; } case "IEnd": { int itoret=IEnd(); if (itoret >= 0) { i = itoret; } break; } case "DRect": { DRect(); break; } case "DOval": { DOval(); break; } case "DHoriz": { DHoriz(strresttrimmed); break; } case "DVerti": { DVerti(strresttrimmed); break; } case "DSlant": { DSlant(); break; } case "LColor": { LColor(strresttrimmed); break; } case "LStyle": { LStyle(strresttrimmed); break; } case "Text": { Text(strrestnontrim); break; } case "AText": { AText(strrestnontrim); break; } case "TextWild": { Text(strrestwild); break; } case "ATextWild": { AText(strrestwild); break; } case "DSingle": { getvalue_seti("#U", DSingle(strresttrimmed)); break; } case "DSingleWild": { getvalue_seti("#U", DSingle(strrestwild)); break; } case "DText": { getvalue_seti("#U", DText(strresttrimmed, false)); break; } case "ResetColumn": { dtcolumn=0; break; } case "DTable": { getvalue_seti("#U", DText(strresttrimmed, true)); break; } case "TColor": { TColor(strresttrimmed); break; } case "TFont": { TFont(strresttrimmed); break; } case "Font": { TFont(strresttrimmed); break; } case "DImage": { DImage(strresttrimmed); break; } case "Dump": { Dump(strresttrimmed); break; } case "ToText": { ToText(strresttrimmed); break; } case "PageToText": { PageToText(strresttrimmed); break; } } } return active; } // ========================================================================== string getessencetrim(string all) { int i = all.IndexOf("//"); if (i >= 0) { return all.Substring(0, i).Trim(); } else { return all.Trim(); } } // ========================================================================== string getessence(string all) { int i = all.IndexOf("//"); if (i >= 0) { return all.Substring(0, i); } else { return all; } } // ========================================================================== void DImage(string strall) { List lst = new List(); for(; ; ) { int i=strall.IndexOf(","); if (i < 0) { lst.Add(strall.Trim()); break; } lst.Add(strall.Substring(0, i)); strall = strall.Substring(i + 1).Trim(); } Image img = Image.FromFile(lst[4]); globalg.DrawImage(img, getvalue(lst[0]), getvalue(lst[1]), getvalue(lst[2]), getvalue(lst[3])); } // ========================================================================== public void Iter(string str, int i) { int itoiter=(int)getvalue(str); beginbrackets.Add(i); iters.Add(itoiter); } // ========================================================================== public int IEnd() { int ilevel = beginbrackets.Count-1; iters[ilevel]--; if (iters[ilevel] > 0) { return beginbrackets[ilevel]; } else { beginbrackets.RemoveAt(ilevel); iters.RemoveAt(ilevel); return -1; } } // ========================================================================== public void Text(string str) { globalstr = str; dtcolumn = 0; } // ========================================================================== public void AText(string str) { globalstr += "\r"+str; dtcolumn = 0; } // ========================================================================== public void DHoriz(string strall) { strall = strall.Trim(); int ib = strall.IndexOf(";"); if (ib < 0) { DHorizkernel(strall); return; } else { Let(strall.Substring(0, ib)); DHorizkernel(strall.Substring(ib+1)); return; } } // ========================================================================== void DHorizkernel(string strall) { int ic = strall.IndexOf(","); if (ic < 0) { DHoriz_each(strall); return; } string str = strall.Substring(0, ic); DHoriz_each(str); strall = strall.Substring(ic+1); DHorizkernel(strall); } // ========================================================================== void DHoriz_each(string stry) { float y = getvalue(stry); globalg.DrawLine(globalpen, new PointF(_istr["#W"], y), new PointF(_istr["#E"], y)); } // ========================================================================== public void DVerti(string strall) { strall = strall.Trim(); int ib = strall.IndexOf(";"); if (ib < 0) { DVertikernel(strall); return; } else { Let(strall.Substring(0, ib)); DVertikernel(strall.Substring(ib+1)); return; } } // ========================================================================== void DVertikernel(string strall) { int ic = strall.IndexOf(","); if (ic < 0) { DVerti_each(strall); return; } string str = strall.Substring(0, ic); DVerti_each(str); strall = strall.Substring(ic+1); DVertikernel(strall); } // ========================================================================== void DVerti_each(string strx) { float x = getvalue(strx); globalg.DrawLine(globalpen, new PointF(x, _istr["#N"]), new PointF(x, _istr["#S"])); } // ========================================================================== public void DSlant() { Graphics g = globalg; Pen pen = globalpen; g.DrawLine(pen, _istr["#W"], _istr["#N"], _istr["#E"], _istr["#S"]); } // ========================================================================== public void TFont(string ffall) { int i = ffall.IndexOf(";"); if (i >= 0) { TFont_kernel(ffall.Substring(0,i).Trim()); TFont_kernel(ffall.Substring(i+1).Trim()); } else { TFont_kernel(ffall); } } // ========================================================================== void TFont_kernel(string ffall) { List lst = new List(); for( ; ; ) { int i=ffall.IndexOf(","); if (i < 0) { lst.Add(ffall.Trim()); break; } lst.Add(ffall.Substring(0, i)); ffall = ffall.Substring(i + 1).Trim(); } if(lst.Count == 1) { TFonteach(lst[0]); } else if(lst.Count == 2) { TFonteach(lst[0]); TFonteach(lst[1]); } else if(lst.Count == 3) { int ir = int.Parse(lst[0]), ig = int.Parse(lst[1]), ib = int.Parse(lst[2]); globalpen = new Pen(Color.FromArgb(ir, ig, ib), globalpen.Width); } } // ========================================================================== void TFonteach(string ff) { try{ globalfontsize=getvalue(ff); return; } catch { } globalfontfamily = ff; } // ========================================================================== Color globalFColor = Color.Yellow; public void LColor(string rall) { List lst = new List(); for( ; ; ) { int i=rall.IndexOf(","); if (i < 0) { lst.Add(rall.Trim()); break; } lst.Add(rall.Substring(0, i).Trim()); rall = rall.Substring(i + 1); } globalpen = new Pen(Color.FromArgb( int.Parse(lst[0]), int.Parse(lst[1]), int.Parse(lst[2])), globalpen.Width); } // ========================================================================== public void TColor(string rall) { List lst = new List(); for( ; ; ) { int i=rall.IndexOf(","); if (i < 0) { lst.Add(rall.Trim()); break; } lst.Add(rall.Substring(0, i).Trim()); rall = rall.Substring(i + 1); } globaltextbrush = new SolidBrush(Color.FromArgb( int.Parse(lst[0]), int.Parse(lst[1]), int.Parse(lst[2]))); } // ========================================================================== public void Fcolor(string rall) { List lst = new List(); for( ; ; ) { int i=rall.IndexOf(","); if (i < 0) { lst.Add(rall.Trim()); break; } lst.Add(rall.Substring(0, i).Trim()); rall = rall.Substring(i + 1); } globalFColor = Color.FromArgb( int.Parse(lst[0]), int.Parse(lst[1]), int.Parse(lst[2])); } // ========================================================================== public void LStyle(string str) { if (str == "Dot") { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; } else if (str == "Dash") { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; } else if (str == "DashDot") { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; } else if (str == "DashDotDot") { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; } else if (str == "Solid") { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; } } // ========================================================================== void LStyle(float f) { if (f == 1) { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; } else if (f == 2) { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; } else if (f == 3) { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; } else if (f == 4) { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; } else { globalpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; } } // ========================================================================== int dtcolumn = 0; public float DText(string all, bool tablef) { int ia = all.IndexOf(","), ib = all.IndexOf(",", ia + 1), ic, id = all.Length; float x = getvalue(all.Substring(0, ia)); if (ib < 0) { ib = id; ic = id; } else { ic = all.IndexOf(",", ib + 1); if (ic < 0) { ic = id; } } string strhandy = all.Substring(ia + 1, ib - ia - 1); float jpre = getvalue(strhandy); float itvl = 0; if (ib < ic) { itvl = getvalue(all.Substring(ib + 1, ic - ib - 1)); } float fd = 2000; if (ic < id) { fd = getvalue(all.Substring(ic + 1, id - ic - 1)); } string remall = globalstr; /* float toret= DText_kernel(x, jpre, itvl, fd, rem, tablef); dtcolumn++; return toret; } // ========================================================================== float DText_kernel(float x, float jpre, float itvl, float w, string remall, bool tablef) { */ float r = _istr["#R"], h = _istr["#H"], w=fd; string strthecolumn = ""; for (; ; ) { if (remall == "") { break; } int jr = remall.IndexOf("\r"); if (jr < 0) { jr = remall.Length; } string strlinenow = remall.Substring(0,jr); if (jr >= remall.Length) { remall = ""; } else { remall = remall.Substring(jr + 1); } string rem= strlinenow; if (tablef) { for (int i=dtcolumn; i > 0; i--) { int ir = rem.IndexOf(","); if (ir < 0) { rem = ""; break; } rem = rem.Substring(ir + 1); } int irn = rem.IndexOf(","); if (irn < 0) { irn=rem.Length; } rem=rem.Substring(0, irn); } if (strthecolumn != "") { strthecolumn += "\r"; } strthecolumn += rem; } float fontsize = globalfontsize; Font font = new Font(globalfontfamily, fontsize); Graphics g = globalg; float jprefirst = jpre; jpre += r/2; List lps = new List(); float wtotal = r/2, hnw = 0; for (int i=0; i".IndexOf(str) >= 0 || i > 0 && "((「『{{[【[{《⦅≪〈〔<".IndexOf(strthecolumn.Substring(i - 1, 1)) >= 0) { float wpre = x + wtotal - lps[lps.Count - 1].X; float hhere=nopadH; // === to usual height !!! if (h != 0) { hhere = h; } jpre += hhere; lps[lps.Count - 1] = new PointF(x + r / 2, jpre); lps.Add(new PointF(x + r / 2 + wpre, jpre)); wtotal = wpre + r / 2 + nopadW; } else { float hhere=nopadH; // === to usual height !!! if (h != 0) { hhere = h; } jpre += hhere; lps.Add(new PointF(x+ r/2, jpre)); wtotal = r/2+nopadW; } hnw = nopadH; } for (int i=0; i 0) { DRect_kernel(new PointF(x, jprefirst), new SizeF(w, jafter-jprefirst)); } dtcolumn++; return jafter; } // ========================================================================== public float DSingle(string all) { int ia = all.IndexOf(","), ib = all.IndexOf(",", ia + 1), ic = all.IndexOf(";"); if (ic < 0) { MessageBox.Show("No text for [DSingle] ( " + all + " ), \";\" is needed !!! "); } float x = getvalue(all.Substring(0, ia)), jpre, vpre = 0; if (ib < 0 || ib > ic) { string strhandy = all.Substring(ia + 1, ic - ia - 1); jpre = getvalue(strhandy); } else { if (ic < 0) { ic = all.Length; } string strhandy = all.Substring(ia + 1, ib - ia - 1); jpre = getvalue(strhandy); } if (ib >= 0) { vpre=getvalue( all.Substring(ib + 1, ic - ib - 1)); } string rem = ""; if (ic > 0 && ic < all.Length) { rem=all.Substring(ic+1).Trim(); } if (rem.Length >= 3 && rem.Substring(0,3) == "(現住") { int hl = 1; } if (rem == "") { return jpre; } string remall = rem; // float r = _istr["#R"], h = _istr["#H"]; string strthecolumn = remall; float fontsize = globalfontsize; Font font = new Font(globalfontfamily, fontsize); Graphics g = globalg; float jprefirst = jpre; jpre += r/2; List lps = new List(); float wtotal = r/2; SizeF nopadSizez = TextRenderer.MeasureText(g, strthecolumn.Substring(0, 1), font, new Size(2000, 2000), TextFormatFlags.NoPadding); float sizeH = nopadSizez.Height; for (int i=0; i 0) { SzW = vpre; } wtotal += SzW; } for (int i=0; i lps = new List(); float wtotal = r/2, hnw = 0; for (int i=0; i".IndexOf(str) >= 0 || i > 0 && "((「『{{[【[{《⦅≪〈〔<".IndexOf(strthecolumn.Substring(i - 1, 1)) >= 0) { float wpre = x + wtotal - lps[lps.Count - 1].X; float hhere=nopadSize.Height; // === to usual height !!! if (h != 0) { hhere = h; } jpre += hhere; lps[lps.Count - 1] = new PointF(x + r / 2, jpre); lps.Add(new PointF(x + r / 2 + wpre, jpre)); wtotal = wpre + r / 2 + nopadSize.Width; } else { float hhere=nopadSize.Height; // === to usual height !!! if (h != 0) { hhere = h; } jpre += hhere; lps.Add(new PointF(x+ r/2, jpre)); wtotal = r/2+nopadSize.Width; } hnw = nopadSize.Height; } for (int i=0; i 0) { DRect_kernel(new PointF(x, jprefirst), new SizeF(w, jafter-jprefirst)); } return jafter; } // ========================================================================== public void Dump(string strval) { int ic = strval.IndexOf(","); if(ic >= 0) { string str1 = strval.Substring(0, ic), str2 = strval.Substring(ic + 1); Dump_each(str1.Trim()); Dump(str2.Trim()); } else { Dump_each(strval.Trim()); } } // ========================================================================== public void PageToText(string strval) { globalstr = Page;   dtcolumn = 0; } // ========================================================================== public void ToText(string strval) { bool has = _istr.ContainsKey(strval); if (has) { string str = getvalue(strval).ToString(); globalstr = str; } else { string str = strval+" = (undefined)"; globalstr = str; }   dtcolumn = 0; } // ========================================================================== public void Dump_each(string strval) { bool has = _istr.ContainsKey(strval); if (has) { string str = strval+" = " + getvalue(strval).ToString(); globalg.DrawString(str, new Font("MS ゴシック", 18), new SolidBrush(Color.Blue), 50, ydumper); } else { string str = strval+" = (undefined)"; globalg.DrawString(str, new Font("MS ゴシック", 18), new SolidBrush(Color.Blue), 50, ydumper); } ydumper += 30; } // ========================================================================== public void DOval() { Graphics g = globalg; g.DrawEllipse(globalpen, _istr["#W"], _istr["#N"], _istr["#E"]-_istr["#W"], _istr["#S"]-_istr["#N"]); } // ========================================================================== public void DRect() { PointF pt = new PointF(_istr["#W"], _istr["#N"]); SizeF sz=new SizeF(_istr["#E"]-_istr["#W"], _istr["#S"]-_istr["#N"]); DRect_kernel(pt, sz); } // ========================================================================== void DRect_kernel(PointF pt, SizeF sz) { Graphics g = globalg; Pen pen = globalpen; float r=getvalue("#R"), R=r*2; g.DrawLine(pen, pt.X+r, pt.Y, pt.X + sz.Width-r, pt.Y); g.DrawLine(pen, pt.X + sz.Width, pt.Y+r, pt.X + sz.Width, pt.Y+sz.Height-r); g.DrawLine(pen, pt.X + sz.Width-r, pt.Y+sz.Height, pt.X+r, pt.Y+sz.Height); g.DrawLine(pen, pt.X , pt.Y+sz.Height-r, pt.X , pt.Y+r); if (r > 0) { g.DrawArc(pen, pt.X, pt.Y, R, R, 180, 90); g.DrawArc(pen, pt.X+sz.Width-R, pt.Y, R, R, 270, 90); g.DrawArc(pen, pt.X+sz.Width-R, pt.Y+sz.Height-R, R, R, 0, 90); g.DrawArc(pen, pt.X, pt.Y+sz.Height-R, R, R, 90, 90); } } // ========================================================================== public void Let(string strall ) { int it = strall.IndexOf("//"); if (it >= 0) { strall = strall.Substring(0, it); } strall = strall.Trim(); int ic = strall.IndexOf(","); if (ic < 0) { getvaluestrict(strall); return; } string str = strall.Substring(0, ic); getvaluestrict(str); strall = strall.Substring(ic+1); Let(strall); } // ========================================================================== int getend(string all, int nb) { int itot = 1; for (int i=nb+1; i= 0 && (nb < ni || ni < 0)) { int eb = getend(all, nb); float ta= getvalue(all.Substring(nb + 1, eb - nb - 1)); float tb = getvalue(all.Substring(eb + 1)); return ta + tb; } if (ni >= 0) { float fgot=getvalue(all.Substring(ni + 1).Trim()); string strx = all.Substring(0, ni).Trim(); getvalue_seti(strx, fgot); return fgot; } else { return getvalue_geti(all); } } // ========================================================================== void getvalue_seti(string str, float i) { if (_istr.ContainsKey(str)) { if(str.Substring(0, 1) != "#") { System.Windows.Forms.MessageBox.Show( "redifinition on "+str+" to "+i.ToString()); } else if (str.Length > 1 && str.Substring(1, 1) == "D") { LStyle(i); } else if (str.Length > 1 && str.Substring(1, 1) == "T") { Pen newpen=new Pen(globalpen.Color, i); newpen.DashStyle = globalpen.DashStyle; globalpen = newpen; } _istr[str] = i; } else { _istr.Add(str, i); } } // ========================================================================== float getvalue_geti(string str) { float sum1 = 0; for (int i=0; ; ) { str = str.Trim(); if (str.Length == 0) { break; } int ib = str.IndexOf(" ", i); if (ib > 0) { sum1 = geti_knowi(str.Substring(0, ib), sum1); str = str.Substring(ib + 1); } else { sum1 = geti_knowi(str, sum1); break; } } return sum1; } // ========================================================================== float geti_knowi(string str, float sum1) { if (str.Substring(0,1) == "/") { return sum1/geti_answersingle(str.Substring(1)); } else if (str.Substring(0,1) == "*") { return sum1*geti_answersingle(str.Substring(1)); } else if (str.Substring(0,1) == "-") { return sum1-geti_answersingle(str.Substring(1)); } else { return sum1+geti_answersingle(str); } } // ========================================================================== float geti_answersingle(string str) { try { float f=float.Parse(str); return f; } catch { } return _istr[str]; } // ========================================================================== } // ############################################################################## // ------------------------- bottom of file FormMaker.cs(1.1) --------------------------