<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Pango > 原文: [http://zetcode.com/gui/gtksharp/pango/](http://zetcode.com/gui/gtksharp/pango/) 在 GTK# 編程教程的這一部分中,我們將探索 Pango 庫。 Pango 是一個免費的開源計算庫,可高質量呈現國際化文本。 可以使用不同的字體后端,從而允許跨平臺支持。 (維基百科) Pango 提供了用于 Gdk 和 Gtk 的高級字體和文本處理。 ## 簡單的例子 在第一個示例中,我們展示了如何更改標簽小部件的字體。 `quotes.cs` ```cs using Gtk; using System; class SharpApp : Window { private Label label; public SharpApp() : base("Pango") { SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; string text = @"Excess of joy is harder to bear than any amount of sorrow. The more one judges, the less one loves. There is no such thing as a great talent without great will power. "; label = new Label(text); Pango.FontDescription fontdesc = Pango.FontDescription.FromString("Purisa 10"); label.ModifyFont(fontdesc); Fixed fix = new Fixed(); fix.Put(label, 5, 5); Add(fix); ShowAll(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 在上面的代碼示例中,我們有一個帶有三個引號的標簽小部件。 我們將其字體更改為 Purisa 10。 ```cs string text = @"Excess of joy is harder to bear than any amount of sorrow. ... ``` 這是要在標簽中顯示的文本。 ```cs Pango.FontDescription fontdesc = Pango.FontDescription.FromString("Purisa 10"); ``` `FontDescription`用于指定要加載的字體的特征。 `FromString()`方法從字符串表示形式創建新的字體描述。 ```cs label.ModifyFont(fontdesc); ``` 我們將標簽小部件的字體更改為 Purisa 10。 ![Quotations](https://img.kancloud.cn/c1/a4/c1a443f684b4c84be9797ccc9b5d43fb_503x99.jpg) 圖:`Quotations` ## 系統字體 下一個代碼示例顯示`TreeView`小部件中的所有可用字體。 `systemfonts.cs` ```cs using System; using Pango; using Gtk; public class SharpApp : Window { ListStore store; FontFamily[] fam; public SharpApp() : base("System fonts") { BorderWidth = 8; SetDefaultSize(350, 250); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; ScrolledWindow sw = new ScrolledWindow(); sw.ShadowType = ShadowType.EtchedIn; sw.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); Context context = this.CreatePangoContext(); fam = context.Families; store = CreateModel(); TreeView treeView = new TreeView(store); treeView.RulesHint = true; sw.Add(treeView); CreateColumn(treeView); Add(sw); ShowAll(); } void CreateColumn(TreeView treeView) { CellRendererText rendererText = new CellRendererText(); TreeViewColumn column = new TreeViewColumn("FontName", rendererText, "text", Column.FontName); column.SortColumnId = (int) Column.FontName; treeView.AppendColumn(column); } ListStore CreateModel() { ListStore store = new ListStore( typeof(string) ); foreach (FontFamily ff in fam) { store.AppendValues(ff.Name); } return store; } enum Column { FontName } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 該代碼示例顯示了系統上所有可用的字體。 ```cs Context context = this.CreatePangoContext(); ``` 此代碼行創建一個`Pango.Context`對象。 它包含有關文本渲染過程的全局信息。 ```cs fam = context.Families; ``` 從上下文對象中,我們檢索所有可用的字體系列。 ```cs foreach (FontFamily ff in fam) { store.AppendValues(ff.Name); } ``` 在`TreeView`小部件的模型創建期間,我們從字體家族數組中獲取所有字體名稱,并將它們放入列表存儲中。 ![System fonts](https://img.kancloud.cn/2f/4b/2f4b6877339b56fc0f8f1b75c09b291b_358x278.jpg) 圖:系統字體 ## Unicode Pango 用于處理國際化文本。 `unicode.cs` ```cs using Gtk; using System; class SharpApp : Window { public SharpApp() : base("Unicode") { SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; string text = @"Фёдор Михайлович Достоевский родился 30 октября (11 ноября) 1821 года в Москве.Был вторым из 7 детей. Отец, Михаил Андреевич, работал в госпитале для бедных. Мать, Мария Фёдоровна (в девичестве Нечаева), происходила из купеческого рода."; Label label = new Label(text); Pango.FontDescription fontdesc = Pango.FontDescription.FromString("Purisa 10"); label.ModifyFont(fontdesc); Fixed fix = new Fixed(); fix.Put(label, 5, 5); Add(fix); ShowAll(); } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 我們在西里爾字母中顯示一些文本。 ```cs string text = @"Фёдор Михайлович Достоевский родился 30 октября ... ``` 我們可以直接使用 unicode 文本。 ```cs Label label = new Label(text); ``` 我們通常在標簽小部件中使用它。 ![Unicode](https://img.kancloud.cn/65/1a/651a3e3856ffaf07117fc3e278ccad94_628x99.jpg) 圖:Unicode ## 彩色文字 在最后一個示例中,我們將進一步探索 Pango 功能。 我們將在`DrawingArea`小部件上繪制居中的彩色文本。 `coloured.cs` ```cs using System; using Gtk; using Pango; public class SharpApp : Window { public SharpApp () : base ("Australia") { SetDefaultSize(250, 200); SetPosition(WindowPosition.Center); DeleteEvent += delegate { Application.Quit(); }; Gdk.Color white = new Gdk.Color(255, 255, 255); DrawingArea drawingArea = new DrawingArea(); drawingArea.ModifyBg(StateType.Normal, white); drawingArea.ExposeEvent += OnExposeEvent; Add(drawingArea); ShowAll(); } void OnExposeEvent (object sender, ExposeEventArgs a) { DrawingArea drawingArea = sender as DrawingArea; int width = drawingArea.Allocation.Width; Gdk.PangoRenderer renderer = Gdk.PangoRenderer.GetDefault(drawingArea.Screen); renderer.Drawable = drawingArea.GdkWindow; renderer.Gc = drawingArea.Style.BlackGC; Context context = drawingArea.CreatePangoContext(); Pango.Layout layout = new Pango.Layout(context); layout.Width = Pango.Units.FromPixels(width); layout.SetText("Australia"); FontDescription desc = FontDescription.FromString("Serif Bold 20"); layout.FontDescription = desc; renderer.SetOverrideColor(RenderPart.Foreground, new Gdk.Color(200, 30, 30)); layout.Alignment = Pango.Alignment.Center; renderer.DrawLayout(layout, 0, 0); renderer.SetOverrideColor(RenderPart.Foreground, Gdk.Color.Zero); renderer.Drawable = null; renderer.Gc = null; } public static void Main() { Application.Init(); new SharpApp(); Application.Run(); } } ``` 我們繪制水平居中的`"Australia"`文本,顏色為深紅色。 ```cs Gdk.PangoRenderer renderer = Gdk.PangoRenderer.GetDefault(drawingArea.Screen); renderer.Drawable = drawingArea.GdkWindow; renderer.Gc = drawingArea.Style.BlackGC; ``` 我們獲得了屏幕的默認渲染器,并將其設置為繪制。 ```cs Context context = drawingArea.CreatePangoContext(); Pango.Layout layout = new Pango.Layout(context); ``` 我們創建一個`Pango.Layout`。 它是用于布置整個文本塊的高級驅動程序。 ```cs layout.Width = Pango.Units.FromPixels(width); ``` 我們指定布局的寬度。 ```cs layout.SetText("Australia"); ``` 我們設置文本。 ```cs FontDescription desc = FontDescription.FromString("Serif Bold 20"); layout.FontDescription = desc; ``` 我們為布局指定字體。 ```cs renderer.SetOverrideColor(RenderPart.Foreground, new Gdk.Color(200, 30, 30)); layout.Alignment = Pango.Alignment.Center; ``` 我們設置顏色和對齊方式。 ```cs renderer.DrawLayout(layout, 0, 0); ``` 我們繪制 Pango 布局。 ```cs renderer.SetOverrideColor(RenderPart.Foreground, Gdk.Color.Zero); renderer.Drawable = null; renderer.Gc = null; ``` 我們清理資源。 ![Australia](https://img.kancloud.cn/9c/19/9c198413d13873c24483a07ff30de25f_258x228.jpg) 圖:澳大利亞 在 GTK# 編程庫的這一章中,我們使用了 Pango 庫。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看