标签: directwrite

SetLineSpacing()在DirectWrite中不起作用 - 为什么?

我在Direct2D/DirectWrite中渲染文本,但调用SetLineSpacing()TextFormat或TextLayout似乎没有任何效果.有谁知道为什么?

c++ direct2d directwrite

4
推荐指数
1
解决办法
856
查看次数

未解决的外部符号

主要文章有一个头文件和一个源文件.复制这两个文件并添加几个标题后:

#include <Windows.h>
#include <d2d1.h>
#pragma comment(lib, "d2d1")
#include <dwrite.h>
#include <d2d1helper.h>
#include "SafeRelease.h"
Run Code Online (Sandbox Code Playgroud)

//安全的重新发布文件

template<class Interface>
inline void
SafeRelease(
    Interface **ppInterfaceToRelease
    )
{
    if (*ppInterfaceToRelease != NULL)
    {
        (*ppInterfaceToRelease)->Release();

        (*ppInterfaceToRelease) = NULL;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我试图编译这个项目时,我收到一个错误:

错误1错误LNK2019:未解析的外部符号__imp__DWriteCreateFactory @ 12在函数"private:long __thiscall SimpleText :: CreateDeviceIndependentResources(void)"中引用(?CreateDeviceIndependentResources @ SimpleText @@ AAEJXZ)

不知道为什么.所有?标题包括在内.希望你们中的一些人能够帮助解决这个问题.
谢谢.

c++ direct2d directwrite

4
推荐指数
1
解决办法
3076
查看次数

如何使用DWrite测量文本范围?

如何使用DirectWrite获取文本范围?
例如,.Net将其作为FormattedText类的一部分提供.

c# directwrite

3
推荐指数
1
解决办法
2755
查看次数

使用ID2D1RenderTarget :: DrawText时如何获取文本范围

使用Direct2D,我可以使用ID2D1RenderTarget :: DrawText来绘制文本,但是如何在绘制之前获取文本范围?请注意,我希望在Windows 8 RT下执行此操作.

谢谢

directx direct2d directwrite windows-8

3
推荐指数
1
解决办法
801
查看次数

DirectWrite文本位置因字体大小而异

我正在使用DirectWrite将一些文本呈现到窗口.除了使用不同字体大小的定位外,一切似乎都有效:我希望有两个字体大小为v1和v2的文本以及两个带有(x,y)=(0,0)的文本位于左上角,但正如您所见:

在此输入图像描述

"测试"和"X"都不在左上方.

有没有办法让这项工作?

c++ winapi directwrite

3
推荐指数
1
解决办法
2041
查看次数

C++ - DirectWrite:在运行时从文件加载字体

我正在尝试在运行时从文件加载字体并使用 DirectWrite 显示它。以下代码应使用该字体初始化 IDWriteTextFormat 对象:

hr = pDWriteFactory->CreateTextFormat(
            L"Font Family",    // Font family name
            NULL,              // Font collection (NULL sets it to use the system font collection)
                               // Somehow, a custom font collection should be used here, but I don't know how to do that
            DWRITE_FONT_WEIGHT_REGULAR,
            DWRITE_FONT_STYLE_NORMAL,
            DWRITE_FONT_STRETCH_NORMAL,
            16.0f,
            L"en-us",
            &pTextFormat       // IDWriteTextFormat object
        );
Run Code Online (Sandbox Code Playgroud)

它与系统字体完美配合,但我不知道如何加载自定义字体文件。我将不胜感激有关如何实现这一目标的任何示例。

到目前为止我尝试过的:
• 我在 Stackoverflow 上阅读了这篇文章这个问题,但我没有看到应该在哪里传递字体文件的文件路径(因此,我完全没有实现这两个页面上提供的任何代码)
• 我也读过这篇文章,但如果我是对的,它与 DirectWrite (?) 无关(我尝试实现 AddFontResourceEx 方法,但无济于事)
• 最后,该问题的答案建议使用 …

c++ fonts directwrite

3
推荐指数
2
解决办法
4628
查看次数

如何转换DirectWrite文本对象之一,同时保持其他文本对象不变

我在同一个渲染目标上有几个DirectWrite文本对象,我想一次转换其中一个,同时保持其他没有变化,在Direct2D中,有几种类型的转换

  • 渲染目标变换
  • 几何变换
  • 刷变换

我不能使用渲染目标变换,因为它会影响它上面的所有对象

我不能使用几何变换,因为文本不是几何,并且IDWriteTextLayout没有变换方法.

所以对我来说唯一的选择是画笔变换,但是当我尝试使用实心画笔绘制一个变换的矩形时,它仍然在原始位置绘制它(参见下面的代码),sdk demo演示了一个位图画笔变换的例子,所以我的问题是:转换是否适用于其他类型的画笔?像实心刷?

这是我的代码,首先,根据经过的时间计算转换矩阵,然后使用此矩阵转换画笔,最后绘制矩形.请看一下,告诉我是否是这种情况,或者我是否可以用其他方式做到这一点?

VOID CalculateTranslationMatrix(D2D1_MATRIX_3X2_F* matrix) 
{ 
    static float totalTime = 0.0f; 

    // Get start time 
    static DWORD startTime = timeGetTime(); 

    // Get current time 
    DWORD currentTime = timeGetTime(); 

    // Calculate time elapsed 
    float timeElapsed = (currentTime - startTime) * 0.001f; 

    // Accumulate total time elapsed 
    totalTime += timeElapsed; 

    // Build up the translation matrix 
    matrix->_11 = 1.0f; 
    matrix->_12 = 0.0f; 
    matrix->_21 = 0.0f; 
    matrix->_22 = 1.0f; 
    matrix->_31 = totalTime; 
    matrix->_32 = totalTime; 
} …
Run Code Online (Sandbox Code Playgroud)

direct2d directwrite

0
推荐指数
1
解决办法
894
查看次数

我无法从DirectWrite获得此示例以在V2015中运行

我从MS的此页面获得以下示例,但由于此消息,代码未链接:

错误LNK2019:函数_wmain中引用的未解析的外部符号__imp__DWriteCreateFactory @ 12

我重复以下代码以方便阅读:

#include <dwrite.h>
#include <string.h>
#include <stdio.h>
#include <new>

// SafeRelease inline function.
template <class T> inline void SafeRelease(T **ppT)
{
    if (*ppT)
    {
        (*ppT)->Release();
        *ppT = NULL;
    }
}

void wmain()
{
    IDWriteFactory* pDWriteFactory = NULL;

    HRESULT hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory),
            reinterpret_cast<IUnknown**>(&pDWriteFactory)
            );

    IDWriteFontCollection* pFontCollection = NULL;

    // Get the system font collection.
    if (SUCCEEDED(hr))
    {
        hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
    }

    UINT32 familyCount = 0;

    // Get the number of font families in …
Run Code Online (Sandbox Code Playgroud)

c++ windows directwrite

0
推荐指数
1
解决办法
324
查看次数

标签 统计

directwrite ×8

c++ ×5

direct2d ×4

c# ×1

directx ×1

fonts ×1

winapi ×1

windows ×1

windows-8 ×1