public void FontMeasures(string fontName) { var writer = new StringWriter(); writer.WriteLine("public class FontMeasure{0}:FontMeasure {{", fontName); writer.WriteLine("\tpublic override void Make() {"); var font = new Font(fontName, 10); CharacterRange[] characterRanges = { new CharacterRange(0, 0) }; var stringFormat = GdiConverter.GetDefaultStringFormat().Clone() as StringFormat; stringFormat.SetMeasurableCharacterRanges(characterRanges); for (var i = 0x21; i < 0x17e; i++) { var c = char.ConvertFromUtf32(i); if (false) { // something wrong here; gives always 0 var mcrSize = GdiUtils.DeviceContext.MeasureCharacterRanges(c, font, new Rectangle(0, 0, 1000, 1000), stringFormat); ReportDetail("{0}\t{1}", c, mcrSize[0].GetBounds(GdiUtils.DeviceContext).Size.ToXwt()); } var size = GdiUtils.GetTextDimension(font, c, new SizeF()); ReportDetail("{0}\t{1}", c, size.Width); writer.WriteLine("Add({0},{1},{2}); // {3}", i, size.Width, size.Height, c); } ReportDetail(writer.ToString()); }
private async void WindowLoaded(object sender, RoutedEventArgs e) { var songInfo = PipeListener.staticpipelistener.LastPlayedSong; _songcache = songInfo?.Clone() as SongInfo; if (songInfo == null) { await this.ShowMessageAsync("メッセージ", "現在何も再生されていません。\n(注:アプリケーションが起動する前に再生されていた曲は取得できません)"); this.Close(); return; } var isource = new Func <BitmapSource>(() => { try { if (!songInfo.IsAlbumArtAvaliable()) { return(null); } return(GdiUtils.ToImageSource(songInfo.GetAlbumArt())); } catch { return(null); } })(); AlbumArtImage.Source = isource; TweetTextBox.Text = TweetConverter.SongInfoToString(ConfigStore.StaticConfig.TweetFormat, songInfo); TweetTextBox.Focus(); }
public void CanDrawGeometryGraph() { Graph graph = new Graph(); GeometryGraph ge = new GeometryGraph(); graph.GeometryGraph = ge; SugiyamaLayoutSettings sugiyamaSettings = new SugiyamaLayoutSettings { Transformation = PlaneTransformation.Rotation(Math.PI / 2), EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.Spline }, MinNodeHeight = 10, MinNodeWidth = 20, }; sugiyamaSettings.NodeSeparation *= 2; graph.LayoutAlgorithmSettings = sugiyamaSettings; graph.AddNode("A"); graph.AddNode("B"); graph.AddNode("C"); graph.AddNode("D"); graph.AddEdge("A", "B"); foreach (Node n in graph.Nodes) { graph.GeometryGraph.Nodes.Add(new GeometryNode(CurveFactory.CreateRectangle(20, 10, new GeometryPoint()), n)); } foreach (Edge e in graph.Edges) { GeometryNode source = graph.FindGeometryNode(e.SourceNode.Id); GeometryNode target = graph.FindGeometryNode(e.TargetNode.Id); graph.GeometryGraph.Edges.Add(new GeometryEdge(source, target)); } ge.UpdateBoundingBox(); graph.GeometryGraph = ge; using (Bitmap bmp = new Bitmap(400, 400, PixelFormat.Format32bppPArgb)) using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(System.DrawingCore.Color.White); Rectangle rect = new Rectangle(0, 0, 400, 400); //GdiUtils.SetGraphTransform(graph, rect, g); LayeredLayout layout = new LayeredLayout(graph.GeometryGraph, sugiyamaSettings); layout.Run(); GdiUtils.DrawFromGraph(rect, graph.GeometryGraph, g); bmp.Save("graph.bmp", ImageFormat.Bmp); } }
void StyleEditor() { var style = Layout.StyleSheet.ItemStyle.DefaultStyle; var newFont = new FontMemento(style.Font.GetBackend() as System.Drawing.Font); newFont.SizeInPoints = (float)Camera.Matrix.TransformFontSize(newFont.SizeInPoints); editor.Font = gdiFontCache.GetFont(newFont); editor.BorderStyle = BorderStyle.FixedSingle; editor.Multiline = true; editor.ScrollBars = ScrollBars.None; editor.WordWrap = true; editor.BackColor = System.Drawing.Color.FromArgb((int)style.FillColor.ToRgb()); var location = Camera.FromSource(Current.Location); var size = Camera.FromSource(Current.Size); if (Current is IVisualEdge) { location = Camera.FromSource(Current.Shape[Anchor.Center]); var text = Current.Data == null ? "" : Current.Data.ToString(); size = (Size) GdiUtils.GetTextDimension(editor.Font, text, new System.Drawing.SizeF()) ; size.Height = Math.Max(size.Height + 2, (int)newFont.SizeInPoints + 2); size.Width = Math.Max(size.Width + 2, (int)newFont.SizeInPoints * 4); location.X = location.X - size.Width / 2; location.Y = location.Y - size.Height / 2; } editor.Location = location.ToGdi(); editor.Size = size.ToGdi(); editor.AllowDrop = true; editor.DragOver += editor_DragOver; editor.DragDrop += editor_DragDrop; // does not work: //editor.Scale (new SizeF (camera.Matrice.Elements[0], transformer.Matrice.Elements[3])); }