本文整理汇总了C++中IDWriteFactory类的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteFactory类的具体用法?C++ IDWriteFactory怎么用?C++ IDWriteFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDWriteFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: p
D3D11CanvasWindowGraphicsPtr D3D11CanvasWindowGraphics::Create(
HWND hWnd, D3D11DriverPtr driver, CameraPtr camera)
{
D3D11CanvasWindowGraphicsPtr p(new D3D11CanvasWindowGraphics);
p->m_hWnd = hWnd;
p->m_driver = driver;
p->m_camera = camera;
ID3D11Device* pDevice = p->m_driver->GetD3D11Device();
IDXGIFactory1* pDXGIFactory = p->m_driver->GetDXGIFactory();
IDWriteFactory* pDWriteFactory = p->m_driver->GetDWriteFactory();
// Create text format
CHECK_HR(pDWriteFactory->CreateTextFormat(
L"Calibri", NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 24.0f, L"en-US", p->m_textFormat.Receive()));
// Create swap chain
DXGI_SWAP_CHAIN_DESC scd = { 0 };
scd.BufferDesc.Format = BACKBUFFER_FORMAT;
scd.SampleDesc.Count = 1;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
scd.OutputWindow = hWnd;
scd.Windowed = TRUE;
CHECK_HR(pDXGIFactory->CreateSwapChain(pDevice, &scd, p->m_swapChain.Receive()));
p->CreateSwapChainResources();
return p;
}
示例2: defined
void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) {
rec->fMaskFormat = SkMask::kA8_Format;
}
unsigned flagsWeDontSupport = SkScalerContext::kVertical_Flag |
SkScalerContext::kDevKernText_Flag |
SkScalerContext::kForceAutohinting_Flag |
SkScalerContext::kEmbolden_Flag |
SkScalerContext::kLCD_Vertical_Flag;
rec->fFlags &= ~flagsWeDontSupport;
SkPaint::Hinting h = rec->getHinting();
// DirectWrite does not provide for hinting hints.
h = SkPaint::kSlight_Hinting;
rec->setHinting(h);
#if defined(SK_FONT_HOST_USE_SYSTEM_SETTINGS)
IDWriteFactory* factory = sk_get_dwrite_factory();
if (factory != nullptr) {
SkTScopedComPtr<IDWriteRenderingParams> defaultRenderingParams;
if (SUCCEEDED(factory->CreateRenderingParams(&defaultRenderingParams))) {
float gamma = defaultRenderingParams->GetGamma();
rec->setDeviceGamma(gamma);
rec->setPaintGamma(gamma);
rec->setContrast(defaultRenderingParams->GetEnhancedContrast());
}
}
#endif
}
示例3: GetFitCharCount
int CDirectWriteRenderer::GetFitCharCount(LPCWSTR pText, int Length, int Width, CDirectWriteFont &Font)
{
if (pText == nullptr || Length == 0)
return 0;
if (m_pRenderTarget == nullptr)
return 0;
int FitCharCount = 0;
IDWriteFactory *pFactory = m_System.GetDWriteFactory();
if (pFactory != nullptr) {
IDWriteTextFormat *pTextFormat = Font.GetTextFormat();
if (pTextFormat != nullptr) {
IDWriteTextLayout *pTextLayout;
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
if (Length < 0)
Length = ::lstrlenW(pText);
HRESULT hr = pFactory->CreateTextLayout(
pText,
Length,
pTextFormat,
static_cast<float>(Width),
m_pRenderTarget->GetSize().height,
&pTextLayout);
if (SUCCEEDED(hr)) {
Util::CTempBuffer<DWRITE_CLUSTER_METRICS, 256> ClusterMetrics(Length);
UINT32 ClusterCount;
hr = pTextLayout->GetClusterMetrics(ClusterMetrics.GetBuffer(), Length, &ClusterCount);
if (SUCCEEDED(hr)) {
float Pos = 0.0f;
for (UINT32 i = 0; i < ClusterCount; i++) {
Pos += ClusterMetrics[i].width;
if (static_cast<int>(std::ceil(Pos)) > Width)
break;
FitCharCount += ClusterMetrics[i].length;
}
}
pTextLayout->Release();
}
pTextFormat->Release();
}
pFactory->Release();
}
return FitCharCount;
}
示例4: setupLayout
bool setupLayout (const AttributedString& text, const float maxWidth, const float maxHeight,
ID2D1RenderTarget& renderTarget, IDWriteFactory& directWriteFactory,
IDWriteFontCollection& fontCollection, ComSmartPtr<IDWriteTextLayout>& textLayout)
{
// To add color to text, we need to create a D2D render target
// Since we are not actually rendering to a D2D context we create a temporary GDI render target
Font defaultFont;
BOOL fontFound = false;
uint32 fontIndex;
fontCollection.FindFamilyName (defaultFont.getTypeface()->getName().toWideCharPointer(), &fontIndex, &fontFound);
if (! fontFound)
fontIndex = 0;
ComSmartPtr<IDWriteFontFamily> dwFontFamily;
HRESULT hr = fontCollection.GetFontFamily (fontIndex, dwFontFamily.resetAndGetPointerAddress());
ComSmartPtr<IDWriteFont> dwFont;
hr = dwFontFamily->GetFirstMatchingFont (DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL,
dwFont.resetAndGetPointerAddress());
jassert (dwFont != nullptr);
const float defaultFontHeightToEmSizeFactor = getFontHeightToEmSizeFactor (*dwFont);
ComSmartPtr<IDWriteTextFormat> dwTextFormat;
hr = directWriteFactory.CreateTextFormat (defaultFont.getTypefaceName().toWideCharPointer(), &fontCollection,
DWRITE_FONT_WEIGHT_REGULAR, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
defaultFont.getHeight() * defaultFontHeightToEmSizeFactor,
L"en-us", dwTextFormat.resetAndGetPointerAddress());
setTextFormatProperties (text, *dwTextFormat);
{
DWRITE_TRIMMING trimming = { DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0 };
ComSmartPtr<IDWriteInlineObject> trimmingSign;
hr = directWriteFactory.CreateEllipsisTrimmingSign (dwTextFormat, trimmingSign.resetAndGetPointerAddress());
hr = dwTextFormat->SetTrimming (&trimming, trimmingSign);
}
const int textLen = text.getText().length();
hr = directWriteFactory.CreateTextLayout (text.getText().toWideCharPointer(), textLen, dwTextFormat,
maxWidth, maxHeight, textLayout.resetAndGetPointerAddress());
if (FAILED (hr) || textLayout == nullptr)
return false;
const int numAttributes = text.getNumAttributes();
for (int i = 0; i < numAttributes; ++i)
addAttributedRange (*text.getAttribute (i), *textLayout, textLen, renderTarget, fontCollection);
return true;
}
示例5: delegate_dwritefactory
delegate_dwritefactory(IDWriteFactory *inst) : refnum(0), orig_this(inst), mycoll(nullptr)
{
OutputDebugString("delegate_dwritefactory::delegate_dwritefactory");
InitializeCriticalSection(&collcs);
fontfile_collection_loader &loader = fontfile_collection_loader::get_instance();
if (SUCCEEDED(orig_this->RegisterFontCollectionLoader(&loader))) {
EnterCriticalSection(&fontpathscs);
orig_this->CreateCustomFontCollection(&loader, nullptr, 0, &mycoll);
LeaveCriticalSection(&fontpathscs);
}
factories.insert(this);
}
示例6: GetTextMetrics
bool CDirectWriteRenderer::GetTextMetrics(
LPCWSTR pText, int Length, CDirectWriteFont &Font, TextMetrics *pMetrics)
{
if (pText == nullptr || pMetrics == nullptr)
return false;
if (m_pRenderTarget == nullptr)
return false;
HRESULT hr = E_UNEXPECTED;
IDWriteFactory *pFactory = m_System.GetDWriteFactory();
if (pFactory != nullptr) {
IDWriteTextFormat *pTextFormat = Font.GetTextFormat();
if (pTextFormat != nullptr) {
D2D1_SIZE_F Size;
IDWriteTextLayout *pTextLayout;
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
if (Length < 0)
Length = ::lstrlenW(pText);
Size = m_pRenderTarget->GetSize();
hr = pFactory->CreateTextLayout(
pText,
Length,
pTextFormat,
Size.width,
Size.height,
&pTextLayout);
if (SUCCEEDED(hr)) {
DWRITE_TEXT_METRICS Metrics;
hr = pTextLayout->GetMetrics(&Metrics);
if (SUCCEEDED(hr)) {
pMetrics->Width = Metrics.width;
pMetrics->WidthIncludingTrailingWhitespace = Metrics.widthIncludingTrailingWhitespace;
pMetrics->Height = Metrics.height;
}
pTextLayout->Release();
}
pTextFormat->Release();
}
pFactory->Release();
}
return SUCCEEDED(hr);
}
示例7: DwCreateRenderingTarget
FX_BOOL CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, void** renderTarget)
{
if (pBitmap->GetFormat() > FXDIB_Argb) {
return FALSE;
}
IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory;
IDWriteGdiInterop* pGdiInterop = NULL;
IDWriteBitmapRenderTarget* pBitmapRenderTarget = NULL;
IDWriteRenderingParams* pRenderingParams = NULL;
HRESULT hr = S_OK;
hr = pDwFactory->GetGdiInterop(&pGdiInterop);
if (FAILED(hr)) {
goto failed;
}
hr = pGdiInterop->CreateBitmapRenderTarget(NULL, pBitmap->GetWidth(), pBitmap->GetHeight(),
&pBitmapRenderTarget);
if (FAILED(hr)) {
goto failed;
}
hr = pDwFactory->CreateCustomRenderingParams(
1.0f,
0.0f,
1.0f,
DWRITE_PIXEL_GEOMETRY_RGB,
DWRITE_RENDERING_MODE_DEFAULT,
&pRenderingParams
);
if (FAILED(hr)) {
goto failed;
}
hr = pBitmapRenderTarget->SetPixelsPerDip(1.0f);
if (FAILED(hr)) {
goto failed;
}
*(CDwGdiTextRenderer**)renderTarget = FX_NEW CDwGdiTextRenderer(pBitmap, pBitmapRenderTarget, pRenderingParams);
if (*(CDwGdiTextRenderer**)renderTarget == NULL) {
goto failed;
}
SafeRelease(&pGdiInterop);
SafeRelease(&pBitmapRenderTarget);
SafeRelease(&pRenderingParams);
return TRUE;
failed:
SafeRelease(&pGdiInterop);
SafeRelease(&pBitmapRenderTarget);
SafeRelease(&pRenderingParams);
return FALSE;
}
示例8: UpdateRenderingParams
bool CDirectWriteRenderer::UpdateRenderingParams()
{
if (m_pRenderTarget == nullptr)
return false;
bool fUpdated = false;
IDWriteFactory *pFactory = m_System.GetDWriteFactory();
if (pFactory != nullptr) {
IDWriteRenderingParams *pRenderingParams;
HRESULT hr = pFactory->CreateMonitorRenderingParams(m_hMonitor, &pRenderingParams);
if (SUCCEEDED(hr)) {
if (m_RenderingParams.Mask != 0) {
IDWriteRenderingParams *pCustomRenderingParams;
hr = pFactory->CreateCustomRenderingParams(
(m_RenderingParams.Mask & RenderingParams::PARAM_GAMMA) != 0 ?
m_RenderingParams.Gamma : pRenderingParams->GetGamma(),
(m_RenderingParams.Mask & RenderingParams::PARAM_ENHANCED_CONTRAST) != 0 ?
m_RenderingParams.EnhancedContrast : pRenderingParams->GetEnhancedContrast(),
(m_RenderingParams.Mask & RenderingParams::PARAM_CLEARTYPE_LEVEL) != 0 ?
m_RenderingParams.ClearTypeLevel : pRenderingParams->GetClearTypeLevel(),
(m_RenderingParams.Mask & RenderingParams::PARAM_PIXEL_GEOMETRY) != 0 ?
m_RenderingParams.PixelGeometry : pRenderingParams->GetPixelGeometry(),
(m_RenderingParams.Mask & RenderingParams::PARAM_RENDERING_MODE) != 0 ?
m_RenderingParams.RenderingMode : pRenderingParams->GetRenderingMode(),
&pCustomRenderingParams);
if (SUCCEEDED(hr)) {
m_pRenderTarget->SetTextRenderingParams(pCustomRenderingParams);
pCustomRenderingParams->Release();
}
} else {
m_pRenderTarget->SetTextRenderingParams(pRenderingParams);
}
if (SUCCEEDED(hr))
fUpdated = true;
pRenderingParams->Release();
}
pFactory->Release();
}
return fUpdated;
}
示例9: SafeRelease
LPVOID CDWriteExt::DwCreateFontFaceFromStream(uint8_t* pData, FX_DWORD size, int simulation_style)
{
IDWriteFactory* pDwFactory = (IDWriteFactory*)m_pDWriteFactory;
IDWriteFontFile* pDwFontFile = NULL;
IDWriteFontFace* pDwFontFace = NULL;
BOOL isSupportedFontType = FALSE;
DWRITE_FONT_FILE_TYPE fontFileType;
DWRITE_FONT_FACE_TYPE fontFaceType;
UINT32 numberOfFaces;
DWRITE_FONT_SIMULATIONS fontStyle = (DWRITE_FONT_SIMULATIONS)(simulation_style & 3);
HRESULT hr = S_OK;
hr = pDwFactory->CreateCustomFontFileReference(
(void const*)pData,
(UINT32)size,
CDwFontFileLoader::GetLoader(),
&pDwFontFile
);
if (FAILED(hr)) {
goto failed;
}
hr = pDwFontFile->Analyze(
&isSupportedFontType,
&fontFileType,
&fontFaceType,
&numberOfFaces
);
if (FAILED(hr) || !isSupportedFontType || fontFaceType == DWRITE_FONT_FACE_TYPE_UNKNOWN) {
goto failed;
}
hr = pDwFactory->CreateFontFace(
fontFaceType,
1,
&pDwFontFile,
0,
fontStyle,
&pDwFontFace
);
if (FAILED(hr)) {
goto failed;
}
SafeRelease(&pDwFontFile);
return pDwFontFace;
failed:
SafeRelease(&pDwFontFile);
return NULL;
}
示例10: CreateTextFormat
virtual HRESULT STDMETHODCALLTYPE CreateTextFormat(
WCHAR const* fontFamilyName,
IDWriteFontCollection* fontCollection,
DWRITE_FONT_WEIGHT fontWeight,
DWRITE_FONT_STYLE fontStyle,
DWRITE_FONT_STRETCH fontStretch,
FLOAT fontSize,
WCHAR const* localeName,
IDWriteTextFormat** textFormat
)
{
UINT32 index;
BOOL exists;
HRESULT result;
OutputDebugString("delegate_dwritefactory::CreateTextFormat");
OutputDebugStringW(fontFamilyName);
EnterCriticalSection(&collcs);
result = this->mycoll->FindFamilyName(fontFamilyName, &index, &exists);
if (SUCCEEDED(result)) {
result = E_FAIL;
if (exists != FALSE) {
OutputDebugString("delegate_dwritefactory::CreateTextFormat -> mycoll");
result = orig_this->CreateTextFormat(fontFamilyName, this->mycoll, fontWeight, fontStyle, fontStretch, fontSize, localeName, textFormat);
}
}
LeaveCriticalSection(&collcs);
if (FAILED(result)) {
OutputDebugString("delegate_dwritefactory::CreateTextFormat -> fallback");
result = orig_this->CreateTextFormat(fontFamilyName, fontCollection, fontWeight, fontStyle, fontStretch, fontSize, localeName, textFormat);
}
return result;
}
示例11: ToTextAntialiasMode
void
DWriteContext::SetRenderingParams(
const DWriteRenderingParams *params)
{
if (mDWriteFactory == NULL)
return;
IDWriteRenderingParams *renderingParams = NULL;
D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode =
D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
HRESULT hr;
if (params != NULL)
{
hr = mDWriteFactory->CreateCustomRenderingParams(params->gamma,
params->enhancedContrast, params->clearTypeLevel,
ToPixelGeometry(params->pixelGeometry),
ToRenderingMode(params->renderingMode), &renderingParams);
textAntialiasMode = ToTextAntialiasMode(params->textAntialiasMode);
}
else
hr = mDWriteFactory->CreateRenderingParams(&renderingParams);
if (SUCCEEDED(hr) && renderingParams != NULL)
{
SafeRelease(&mRenderingParams);
mRenderingParams = renderingParams;
mTextAntialiasMode = textAntialiasMode;
}
}
示例12: Initialize
HRESULT CDwFontContext::Initialize()
{
if (hr_ == S_FALSE) {
return hr_ = dwriteFactory_->RegisterFontFileLoader(CDwFontFileLoader::GetLoader());
}
return hr_;
}
示例13: CreateEllipsisTrimmingSign
virtual HRESULT STDMETHODCALLTYPE CreateEllipsisTrimmingSign(
IDWriteTextFormat* textFormat,
IDWriteInlineObject** trimmingSign
)
{
return orig_this->CreateEllipsisTrimmingSign(textFormat, trimmingSign);
}
示例14: GetSystemFontCollection
virtual HRESULT STDMETHODCALLTYPE GetSystemFontCollection(
IDWriteFontCollection** fontCollection,
BOOL checkForUpdates = FALSE
)
{
return orig_this->GetSystemFontCollection(fontCollection, checkForUpdates);
}
示例15: CreateMonitorRenderingParams
virtual HRESULT STDMETHODCALLTYPE CreateMonitorRenderingParams(
HMONITOR monitor,
IDWriteRenderingParams** renderingParams
)
{
return orig_this->CreateMonitorRenderingParams(monitor, renderingParams);
}