GVKun编程网logo

可可 – 如何以一定角度绘制NSString?

26

针对可可–如何以一定角度绘制NSString?这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展.net–如何将System::String^转换为std::string?、c#–如何以一定角度

针对可可 – 如何以一定角度绘制NSString?这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展.net – 如何将System :: String ^转换为std :: string?、c# – 如何以一定角度绘制窗口?、CAD如何画一定角度的线段?CAD画一定角度的线段方法、cocoa – 在CGContext中绘制NSAttributedString时看起来很难看的文本等相关知识,希望可以帮助到你。

本文目录一览:

可可 – 如何以一定角度绘制NSString?

可可 – 如何以一定角度绘制NSString?

是否有一组我可以指定的字符串属性,当我调用时会以一定角度绘制文本:

[label drawAtPoint:textStart withAttributes:attributes];

解决方法

这是一个使用变换来旋转绘图上下文的示例.基本上它就像设置颜色或阴影一样,只需确保使用-concat而不是-set.

CGFloat rotateDeg = 4.0f;
NSAffineTransform *rotate = [[NSAffineTransform alloc] init];

[rotate rotateBydegrees:rotateDeg];
[rotate concat];

// Lock focus if needed and draw strings,images here.

[rotate release];

.net – 如何将System :: String ^转换为std :: string?

.net – 如何将System :: String ^转换为std :: string?

所以我在clr中工作,在visual c中创建.net dll.

我这样的代码:

static bool InitFile(System::String^ fileName,System::String^ container)
{
    return enc.InitFile(std::string(fileName),std::string(container));
}

有编码器,normaly resives std :: string.但是如果我从std :: string和C2440中删除通常相同的参数,那么编译器(visual studio)会给出C2664错误. VS告诉我它无法将System :: String ^转换为std :: string.

所以我很伤心……我该怎么做才能将System :: String ^变成std :: string?

更新:

现在有了你的帮助,我有了这样的代码

#include <msclr\marshal.h>
#include <stdlib.h>
#include <string.h>
using namespace msclr::interop;
namespace NsstW
{
  public ref class CFEW
  {
 public:
     CFEW() {}

     static System::String^ echo(System::String^ stringToReturn)
    {
        return stringToReturn;  
    }

     static bool InitFile(System::String^ fileName,System::String^ container)
    {   
        std::string sys_fileName = marshal_as<std::string>(fileName);;
        std::string sys_container = marshal_as<std::string>(container);;
        return enc.InitFile(sys_fileName,sys_container);
    }
...

但是当我尝试编译时,它给了我C4996

错误C4996:’msclr :: interop :: error_reporting_helper< _To_Type,_From_Type> :: marshal_as’:库不支持此转换,或者不包括此转换所需的头文件.有关添加自己的编组方法的信息,请参阅“如何:扩展封送库”的文档.

该怎么办?

解决方法

如果您使用的是VS2008或更新版本,则可以使用 automatic marshaling added to C++非常简单地执行此操作.例如,您可以通过 marshal_as将System :: String ^转换为std :: string:
System::String^ clrstring = "CLR string";
std::string stdString = marshal_as<std::string>(clrstring);

这与用于P / Invoke调用的编组相同.

c# – 如何以一定角度绘制窗口?

c# – 如何以一定角度绘制窗口?

比如这个.

解决方法

不,Windows没有实现这一点.您可以做的最好是使用Region属性为矩形窗口提供任意形状.不会看起来很棒,区域没有抗锯齿.在角度上显示内容取决于您,例如Graphics.RotateTransform().为用户的颈部抽筋声称获得责任保险也由您自己决定.

CAD如何画一定角度的线段?CAD画一定角度的线段方法

CAD如何画一定角度的线段?CAD画一定角度的线段方法

CAD作图里经常会遇到画一定角度的直线,这里给大家详细讲解步骤。

1、打开CAD软件后,点击直线,或输入命令 'line'。

2、画第一个点, 再输入' <30' ,enter,30是与水平线的夹角 ,逆时针为正。

3、在输入线段长度,enter就可以了。

4、如果要 取消这个角度 ,就在第二步后输 入'<',enter 就行。

5、而且可以连续画多条线段。

注意事项:

所画的直线角度都是与水平线的夹角,不要误以为是与上一条直线的夹角。

cocoa – 在CGContext中绘制NSAttributedString时看起来很难看的文本

cocoa – 在CGContext中绘制NSAttributedString时看起来很难看的文本

我想在CoreAnimation图层中显示字符串,但遗憾的是CATextLayer是不够的,主要是因为在使用约束时你很难使用并且你想要包装文本.

我正在使用NSLayoutManager,使用以下代码(PyObjC):

NSGraphicsContext.saveGraphicsstate()

# THIS SOLVES THIS ISSUE
CGContextSetShouldSmoothFonts(ctx,False)

graphics = NSGraphicsContext.graphicsContextWithGraphicsPort_flipped_(ctx,True)
NSGraphicsContext.setCurrentContext_(graphics)

height = size.height
xform = NSAffineTransform.transform();
xform.translateXBy_yBy_(0.0,height)
xform.scaleXBy_yBy_(1.0,-1.0)
xform.concat()

self.textContainer.setContainerSize_(size)

glyphRange = self.layoutManager.glyphRangeForTextContainer_(self.textContainer)

self.layoutManager.drawBackgroundForGlyphRange_atPoint_(glyphRange,topLeft)
self.layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange,topLeft)

NSGraphicsContext.restoreGraphicsstate()

这一切都很好并且有效,但唯一的问题是它会产生看起来很糟糕的文本(虽然它是防腐蚀的).

这是CATextLayer版本:http://i39.tinypic.com/23h0h1d.png

这是NSLayoutManager版本:http://i40.tinypic.com/2vv9rw5.png

我错过了什么?

解决方法

我正在回答这个问题,因为coretext-dev档案无法搜索,Apple的Aki Inoue刚回答了我的问题:

Since CALayer cannot represent subpixel color (aka font smoothing),you need to disable it.
I believe CATextLayer does it by default.

Do CGContextSetShouldSmoothFonts(context,false).

谢谢,Aki!

Milen Dzhumerov的另一个评论:

I don’t believe this is accurate. We’re drawing text into CALayers with subpixel anti-aliasing. You just have to make sure that you’ve drawn behind the text before drawing the text itself. See 07000 for references.

Milen是正确的,如果你事先知道背景颜色,你可以这样做:

CGContextSetRGBFillColor(ctx,r,g,b,a)
CGContextFillRect(ctx,(topLeft,size))
CGContextSetShouldSmoothFonts(ctx,True)

你会得到漂亮的亚像素抗锯齿文本.但是,如果您不知道背景颜色,则需要关闭字体平滑,否则会出现乱码结果.

今天关于可可 – 如何以一定角度绘制NSString?的讲解已经结束,谢谢您的阅读,如果想了解更多关于.net – 如何将System :: String ^转换为std :: string?、c# – 如何以一定角度绘制窗口?、CAD如何画一定角度的线段?CAD画一定角度的线段方法、cocoa – 在CGContext中绘制NSAttributedString时看起来很难看的文本的相关知识,请在本站搜索。

本文标签: