热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在WPFTextBox中指定字母间距或字距?-HowcanIspecifyletterspacingorkerning,inaWPFTextBox?

IdliketomodifythespacingbetweencharactersinaWPFTextBox.Somethingliketheletter-spacin

I'd like to modify the spacing between characters in a WPF TextBox.
Something like the letter-spacing: 5px thing that is available in CSS.
I think it is possible in XAML; what's the simplest way?

我想修改WPF TextBox中字符之间的间距。像字母间距:CSS中可用的5px之类的东西。我认为在XAML中是可能的;什么是最简单的方法?

I found the "Introduction to the GlyphRun Object and Glyphs Element" document, and found it to be exceedingly unhelpful.

我找到了“GlyphRun对象和字形元素简介”文档,发现它非常无益。

This is a code example from that page:

这是该页面的代码示例:



The same documentation page gives this "explanation" for what the Indices property does:

相同的文档页面为Indices属性提供了“解释”:

enter image description here

I have no idea what any of that means. I'm also not sure that Indices is the right thing - the comment in the code speaks of "character widths" which I don't care about. I want to adjust the width between characters.

我不知道这是什么意思。我也不确定指数是否是正确的 - 代码中的注释说的是“字符宽度”,我并不关心。我想调整字符之间的宽度。

Also, there is no example for how to apply a Glyphs element to a TextBox. When I tried it, my WPF test app just crashed.

此外,没有关于如何将Glyphs元素应用于TextBox的示例。当我尝试它时,我的WPF测试应用程序崩溃了。


What I want to do is slightly increase the empty space that appears between drawn characters within a WPF TextBox. The text will vary in length and content. Do I have to modify the Indicies property every time there is a new character? Is there a way to say "make it 20% more space than usual, for every character".

我想要做的是略微增加WPF TextBox中绘制的字符之间出现的空白区域。案文的长度和内容各不相同。每次有新角色时我是否必须修改Indicies属性?有没有办法说“为每个角色增加20%的空间”。

Can anybody help me?

有谁能够帮助我?

3 个解决方案

#1


16  

I tried Glyphs and FontStretch and couldn't easily get the result I was looking for. I was able to come up with an approach that works for my purposes. Maybe it will work for others, as well.

我尝试了Glyphs和FontStretch,并且不能轻易得到我想要的结果。我能够想出一种适合我的目的的方法。也许它也适用于其他人。


    
        
            
        
    
    
        
            
        
    

I can bind to any string and don't need to do any character width detection to set the spacing properly. The right margin is the space between the letters.

我可以绑定到任何字符串,不需要进行任何字符宽度检测来正确设置间距。右边距是字母之间的空格。

Example:

例:

Kerning

#2


1  

is FontStretch an option for you?

FontStretch是你的选择吗?

Otherwise you might want to look into this there is an image, showing what advance width means. Though I have not done this before and don't know if this works increasing right and left side bearings might be what you want!

否则你可能想看一下有一个图像,显示提前宽度的含义。虽然我之前没有这样做,但不知道这是否有效,左右侧轴承可能是你想要的!

#3


-1  

For what its worth . . .

物有所值 。 。 。

If you have the option to switch your implementation to RichTextBox, this might be easier than the work-around you found Sept 2013. I just tried it for my own needs and it works for what I need. I do not see a way with RichTextBox to control kerning of individual spaces like typesetters do. But TextBox was eating additional spaces (consolidating multiple adjacent spaces to a single space) like HTML. I needed for the spaces to display the same amount of spacing as is in my text String, and RichTextBox does this.

如果您可以选择将实现切换到RichTextBox,这可能比您在2013年9月找到的解决方案更容易。我只是根据自己的需要尝试它,它可以满足我的需求。我没有看到使用RichTextBox来控制像排版者这样的单个空格的字距。但TextBox正在占用额外的空间(将多个相邻的空间合并到一个空间),就像HTML一样。我需要空格显示与文本字符串相同的间距,RichTextBox执行此操作。


I'm no expert, but it seems you can't specify the text content in XAML. I had to specify it in a code-behind event:

我不是专家,但似乎你无法在XAML中指定文本内容。我不得不在代码隐藏事件中指定它:

this.MyRichTextBox.AppendText("V A R I E D      S P A C E S");

推荐阅读
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • 本文介绍了如何在Azure应用服务实例上获取.NetCore 3.0+的支持。作者分享了自己在将代码升级为使用.NET Core 3.0时遇到的问题,并提供了解决方法。文章还介绍了在部署过程中使用Kudu构建的方法,并指出了可能出现的错误。此外,还介绍了开发者应用服务计划和免费产品应用服务计划在不同地区的运行情况。最后,文章指出了当前的.NET SDK不支持目标为.NET Core 3.0的问题,并提供了解决方案。 ... [详细]
  • 本文介绍了Windows Vista操作系统中的用户账户保护功能,该功能是为了增强系统的安全性而设计的。通过对Vista测试版的体验,可以看到系统在安全性方面的进步。该功能的引入,为用户的账户安全提供了更好的保障。 ... [详细]
  • imnewtotheswiftandxcodeworld,soimhavingaproblemtryingtointegrateapackagetomypro ... [详细]
author-avatar
cshaadi_915
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有