+++ /dev/null
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include "stdafx.h"\r
-#include <vector>\r
-\r
-#include "DirectWriteException.h"\r
-#include "../direct2d/Matrix3x2.h"\r
-#include "../stack_array.h"\r
-\r
-#include "FactoryDW.h"\r
-#include "FontCollection.h"\r
-#include "FontFile.h"\r
-#include "FontFace.h"\r
-#include "GdiInterop.h"\r
-#include "GlyphRunDW.h"\r
-#include "GlyphRunAnalysis.h"\r
-#include "IFontCollectionLoader.h"\r
-#include "IFontFileLoader.h"\r
-#include "InlineObject.h"\r
-#include "NumberSubstitution.h"\r
-#include "RenderingParameters.h"\r
-#include "TextAnalyzer.h"\r
-#include "TextFormat.h"\r
-#include "TextLayout.h"\r
-\r
-const IID IID_IDWriteFactory = __uuidof(IDWriteFactory);\r
-\r
-using namespace System;\r
-using namespace System::Runtime::InteropServices;\r
-\r
-namespace SlimDX\r
-{\r
-namespace DirectWrite\r
-{\r
- Factory::Factory()\r
- {\r
- Init( FactoryType::Shared );\r
- }\r
-\r
- Factory::Factory( FactoryType factoryType )\r
- {\r
- Init( factoryType );\r
- }\r
-\r
- void Factory::Init( FactoryType factoryType )\r
- {\r
- IDWriteFactory *factory = NULL;\r
-\r
- if( RECORD_DW( DWriteCreateFactory( static_cast<DWRITE_FACTORY_TYPE>( factoryType ), IID_IDWriteFactory, reinterpret_cast<IUnknown**>( &factory ) ) ).IsFailure )\r
- throw gcnew DirectWriteException( Result::Last );\r
-\r
- Construct( factory );\r
- }\r
-\r
- FontCollection ^Factory::GetSystemFontCollection(bool checkForUpdates)\r
- {\r
- IDWriteFontCollection *collection = 0;\r
- if (RECORD_DW(InternalPointer->GetSystemFontCollection(&collection, checkForUpdates ? TRUE : FALSE)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return FontCollection::FromPointer(collection);\r
- }\r
-\r
- FontCollection ^Factory::CreateCustomFontCollection(IFontCollectionLoader ^loader, IntPtr collectionKey, int collectionKeySize)\r
- {\r
- IDWriteFontCollection *collection = 0;\r
- IFontCollectionLoaderShim *shim = IFontCollectionLoaderShim::CreateInstance(loader);\r
- if (RECORD_DW(InternalPointer->CreateCustomFontCollection(shim, collectionKey.ToPointer(), collectionKeySize, &collection)).IsFailure)\r
- {\r
- shim->Release();\r
- return nullptr;\r
- }\r
- return FontCollection::FromPointer(collection);\r
- }\r
-\r
- FontFile ^Factory::CreateCustomFontFileReference(IntPtr fontFileReferenceKey, int fontFileReferenceKeySize, IFontFileLoader ^loader)\r
- {\r
- IDWriteFontFile *file = 0;\r
- IFontFileLoaderShim *shim = IFontFileLoaderShim::CreateInstance(loader);\r
- if (RECORD_DW(InternalPointer->CreateCustomFontFileReference(fontFileReferenceKey.ToPointer(), fontFileReferenceKeySize, shim, &file)).IsFailure)\r
- {\r
- shim->Release();\r
- return nullptr;\r
- }\r
- return FontFile::FromPointer(file);\r
- }\r
-\r
- RenderingParameters ^Factory::CreateCustomRenderingParameters(\r
- float gamma, float enhancedContrast, float clearTypeLevel,\r
- PixelGeometry pixelGeometry, RenderingMode renderingMode)\r
- {\r
- IDWriteRenderingParams *params = 0;\r
- if (RECORD_DW(InternalPointer->CreateCustomRenderingParams(gamma, enhancedContrast, clearTypeLevel,\r
- static_cast<DWRITE_PIXEL_GEOMETRY>(pixelGeometry),\r
- static_cast<DWRITE_RENDERING_MODE>(renderingMode), ¶ms)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return RenderingParameters::FromPointer(params);\r
- }\r
-\r
- static TextLayout ^CreateGdiCompatibleTextLayoutInternal(IDWriteFactory *factory,\r
- String ^text, TextFormat ^textFormat,\r
- float layoutWidth, float layoutHeight, float pixelsPerDip,\r
- DWRITE_MATRIX *transform, bool useGdiNatural)\r
- {\r
- pin_ptr<const wchar_t> pinnedText = PtrToStringChars(text);\r
-\r
- IDWriteTextLayout *layout = 0;\r
- if (RECORD_DW(factory->CreateGdiCompatibleTextLayout(pinnedText, text->Length,\r
- textFormat->InternalPointer, layoutWidth, layoutHeight, pixelsPerDip,\r
- transform, useGdiNatural ? TRUE : FALSE, &layout)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return TextLayout::FromPointer(layout); \r
- }\r
-\r
- TextLayout ^Factory::CreateGdiCompatibleTextLayout(String ^text, TextFormat ^textFormat,\r
- float layoutWidth, float layoutHeight, float pixelsPerDip, bool useGdiNatural)\r
- {\r
- return CreateGdiCompatibleTextLayoutInternal(InternalPointer, text, textFormat,\r
- layoutWidth, layoutHeight, pixelsPerDip, 0, useGdiNatural);\r
- }\r
- TextLayout ^Factory::CreateGdiCompatibleTextLayout(String ^text, TextFormat ^textFormat,\r
- float layoutWidth, float layoutHeight, float pixelsPerDip,\r
- SlimDX::Direct2D::Matrix3x2 transform, bool useGdiNatural)\r
- {\r
- return CreateGdiCompatibleTextLayoutInternal(InternalPointer, text, textFormat,\r
- layoutWidth, layoutHeight, pixelsPerDip,\r
- reinterpret_cast<DWRITE_MATRIX *>(&transform), useGdiNatural);\r
- }\r
- InlineObject ^Factory::CreateEllipsisTrimmingSign(TextFormat ^textFormat)\r
- {\r
- IDWriteInlineObject *obj = 0;\r
- if (RECORD_DW(InternalPointer->\r
- CreateEllipsisTrimmingSign(textFormat->InternalPointer, &obj)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return InlineObject::FromPointer(obj);\r
- }\r
- FontFace ^Factory::CreateFontFace(FontFaceType fontFaceType, array<FontFile^> ^fontFiles, int faceIndex, FontSimulations fontFaceSimulationFlags)\r
- {\r
- std::vector<IDWriteFontFile *> nativeFontFiles;\r
- nativeFontFiles.resize(fontFiles->Length);\r
- for (int i = 0; i < fontFiles->Length; i++)\r
- {\r
- nativeFontFiles[i] = fontFiles[i]->InternalPointer;\r
- }\r
- IDWriteFontFace *fontFace;\r
- if (RECORD_DW(InternalPointer->CreateFontFace(static_cast<DWRITE_FONT_FACE_TYPE>(fontFaceType),\r
- static_cast<UINT32>(nativeFontFiles.size()), &nativeFontFiles[0],\r
- faceIndex, static_cast<DWRITE_FONT_SIMULATIONS>(fontFaceSimulationFlags),\r
- &fontFace)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return FontFace::FromPointer(fontFace);\r
- }\r
-\r
- static FontFile ^CreateFontFileReferenceInternal(IDWriteFactory *factory, String ^filePath, ::FILETIME const *fileTime)\r
- {\r
- pin_ptr<const wchar_t> pinnedText = PtrToStringChars(filePath);\r
-\r
- IDWriteFontFile *fontFile = 0;\r
- if (RECORD_DW(factory->CreateFontFileReference(pinnedText, fileTime, &fontFile)).IsFailure)\r
- return nullptr;\r
-\r
- return FontFile::FromPointer(fontFile);\r
- }\r
-\r
- FontFile ^Factory::CreateFontFileReference(String ^filePath)\r
- {\r
- return CreateFontFileReferenceInternal(InternalPointer, filePath, 0);\r
- }\r
- FontFile ^Factory::CreateFontFileReference(String ^filePath, ComTypes::FILETIME fileTime)\r
- {\r
- return CreateFontFileReferenceInternal(InternalPointer, filePath, reinterpret_cast<::FILETIME *>(&fileTime));\r
- }\r
-\r
- static GlyphRunAnalysis ^CreateGlyphRunAnalysisInternal(IDWriteFactory *factory,\r
- GlyphRun ^glyphRun, float pixelsPerDip, DWRITE_MATRIX *transform,\r
- RenderingMode renderingMode, MeasuringMode measuringMode,\r
- float baselineOriginX, float baselineOriginY)\r
- {\r
- stack_array<UINT16> indices;\r
- stack_array<FLOAT> advances;\r
- stack_array<DWRITE_GLYPH_OFFSET> offsets;\r
- DWRITE_GLYPH_RUN nativeGlyphRun = glyphRun->ToUnmanaged(indices, advances, offsets);\r
- IDWriteGlyphRunAnalysis *analysis = 0;\r
- if (RECORD_DW(factory->CreateGlyphRunAnalysis(&nativeGlyphRun,\r
- pixelsPerDip, transform,\r
- static_cast<DWRITE_RENDERING_MODE>(renderingMode),\r
- static_cast<DWRITE_MEASURING_MODE>(measuringMode),\r
- baselineOriginX, baselineOriginY, &analysis)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return GlyphRunAnalysis::FromPointer(analysis);\r
- }\r
-\r
- GlyphRunAnalysis ^Factory::CreateGlyphRunAnalysis(GlyphRun ^glyphRun, float pixelsPerDip,\r
- RenderingMode renderingMode, MeasuringMode measuringMode,\r
- float baselineOriginX, float baselineOriginY)\r
- {\r
- return CreateGlyphRunAnalysisInternal(InternalPointer,\r
- glyphRun, pixelsPerDip, 0, renderingMode, measuringMode,\r
- baselineOriginX, baselineOriginY);\r
- }\r
- GlyphRunAnalysis ^Factory::CreateGlyphRunAnalysis(GlyphRun ^glyphRun,\r
- float pixelsPerDip, Matrix3x2 transform,\r
- RenderingMode renderingMode, MeasuringMode measuringMode,\r
- float baselineOriginX, float baselineOriginY)\r
- {\r
- return CreateGlyphRunAnalysisInternal(InternalPointer,\r
- glyphRun, pixelsPerDip, reinterpret_cast<DWRITE_MATRIX *>(&transform),\r
- renderingMode, measuringMode,\r
- baselineOriginX, baselineOriginY);\r
- }\r
-\r
- RenderingParameters ^Factory::CreateMonitorRenderingParameters(IntPtr monitor)\r
- {\r
- IDWriteRenderingParams *params = 0;\r
- if (RECORD_DW(InternalPointer->CreateMonitorRenderingParams(static_cast<HMONITOR>(monitor.ToPointer()), ¶ms)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return RenderingParameters::FromPointer(params);\r
- }\r
-\r
- NumberSubstitution ^Factory::CreateNumberSubstitution(NumberSubstitutionMethod method, String ^localeName, bool ignoreUserOverride)\r
- {\r
- pin_ptr<const wchar_t> pinnedText = PtrToStringChars(localeName);\r
-\r
- IDWriteNumberSubstitution *sub = 0;\r
- if (RECORD_DW(InternalPointer->CreateNumberSubstitution(\r
- static_cast<DWRITE_NUMBER_SUBSTITUTION_METHOD>(method), pinnedText,\r
- ignoreUserOverride ? TRUE : FALSE, &sub)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return NumberSubstitution::FromPointer(sub);\r
- }\r
-\r
- RenderingParameters ^Factory::CreateRenderingParameters()\r
- {\r
- IDWriteRenderingParams *params = 0;\r
- if (RECORD_DW(InternalPointer->CreateRenderingParams(¶ms)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return RenderingParameters::FromPointer(params);\r
- }\r
-\r
- TextAnalyzer ^Factory::CreateTextAnalyzer()\r
- {\r
- IDWriteTextAnalyzer *analyzer = 0;\r
- if (RECORD_DW(InternalPointer->CreateTextAnalyzer(&analyzer)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return TextAnalyzer::FromPointer(analyzer);\r
- }\r
-\r
- static TextFormat ^CreateTextFormatInternal(IDWriteFactory *factory,\r
- String ^fontFamilyName, IDWriteFontCollection *fontCollection,\r
- FontWeight fontWeight, FontStyle fontStyle, FontStretch fontStretch, float fontSize, String ^localeName)\r
- {\r
- pin_ptr<const wchar_t> pinnedText = PtrToStringChars(localeName);\r
- pin_ptr<const wchar_t> pinnedName = PtrToStringChars(fontFamilyName);\r
-\r
- IDWriteTextFormat *format = 0;\r
- if (RECORD_DW(factory->CreateTextFormat(pinnedName,\r
- fontCollection, static_cast<DWRITE_FONT_WEIGHT>(fontWeight),\r
- static_cast<DWRITE_FONT_STYLE>(fontStyle),\r
- static_cast<DWRITE_FONT_STRETCH>(fontStretch),\r
- fontSize, pinnedText, &format)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return TextFormat::FromPointer(format);\r
- }\r
-\r
- TextFormat ^Factory::CreateTextFormat(String ^fontFamilyName,\r
- FontWeight fontWeight, FontStyle fontStyle, FontStretch fontStretch,\r
- float fontSize, String ^localeName)\r
- {\r
- return CreateTextFormatInternal(InternalPointer, fontFamilyName, 0,\r
- fontWeight, fontStyle, fontStretch, fontSize, localeName);\r
- }\r
-\r
- TextFormat ^Factory::CreateTextFormat(String ^fontFamilyName, FontCollection ^fontCollection,\r
- FontWeight fontWeight, FontStyle fontStyle, FontStretch fontStretch,\r
- float fontSize, String ^localeName)\r
- {\r
- return CreateTextFormatInternal(InternalPointer, fontFamilyName,\r
- fontCollection->InternalPointer,\r
- fontWeight, fontStyle, fontStretch, fontSize, localeName);\r
- }\r
-\r
- TextLayout ^Factory::CreateTextLayout(String ^text, TextFormat ^textFormat, float maxWidth, float maxHeight)\r
- {\r
- pin_ptr<const wchar_t> pinnedText = PtrToStringChars(text);\r
-\r
- IDWriteTextLayout *layout = 0;\r
- if (RECORD_DW(InternalPointer->CreateTextLayout(pinnedText, text->Length,\r
- textFormat->InternalPointer, maxWidth, maxHeight, &layout)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return TextLayout::FromPointer(layout);\r
- }\r
-\r
- Typography ^Factory::CreateTypography()\r
- {\r
- IDWriteTypography *typography;\r
- if (RECORD_DW(InternalPointer->CreateTypography(&typography)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return Typography::FromPointer(typography);\r
- }\r
-\r
- GdiInterop ^Factory::GetGdiInterop()\r
- {\r
- IDWriteGdiInterop *gdiInterop;\r
- if (RECORD_DW(InternalPointer->GetGdiInterop(&gdiInterop)).IsFailure)\r
- {\r
- return nullptr;\r
- }\r
- return GdiInterop::FromPointer(gdiInterop);\r
- }\r
-\r
- Result Factory::RegisterFontCollectionLoader(IFontCollectionLoader ^loader)\r
- {\r
- IFontCollectionLoaderShim *shim = IFontCollectionLoaderShim::CreateInstance(loader);\r
- return RECORD_DW(InternalPointer->RegisterFontCollectionLoader(shim));\r
- }\r
-\r
- Result Factory::RegisterFontFileLoader(IFontFileLoader ^loader)\r
- {\r
- IFontFileLoaderShim *shim = IFontFileLoaderShim::CreateInstance(loader);\r
- return RECORD_DW(InternalPointer->RegisterFontFileLoader(shim));\r
- }\r
-\r
- Result Factory::UnregisterFontCollectionLoader(IFontCollectionLoader ^loader)\r
- {\r
- IFontCollectionLoaderShim *shim = IFontCollectionLoaderShim::CreateInstance(loader);\r
- return RECORD_DW(InternalPointer->UnregisterFontCollectionLoader(shim));\r
- }\r
-\r
- Result Factory::UnregisterFontFileLoader(IFontFileLoader ^loader)\r
- {\r
- IFontFileLoaderShim *shim = IFontFileLoaderShim::CreateInstance(loader);\r
- return RECORD_DW(InternalPointer->UnregisterFontFileLoader(shim));\r
- }\r
-\r
-}\r
-}\r