diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.cpp b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.cpp index 1f7baa3590e..16684419a67 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.cpp +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.cpp @@ -6,16 +6,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface { - DWRITE_FACTORY_TYPE DWriteTypeConverter::Convert(FactoryType factoryType) - { - switch(factoryType) - { - case FactoryType::Shared : return DWRITE_FACTORY_TYPE_SHARED; - case FactoryType::Isolated : return DWRITE_FACTORY_TYPE_ISOLATED; - default : throw gcnew System::InvalidOperationException(); - } - } - FontWeight DWriteTypeConverter::Convert(DWRITE_FONT_WEIGHT fontWeight) { // The commented cases are here only for completeness so that the code captures all the possible enum values. @@ -373,29 +363,4 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface } } - DWRITE_MEASURING_MODE DWriteTypeConverter::Convert(TextFormattingMode measuringMode) - { - switch(measuringMode) - { - case TextFormattingMode::Ideal : return DWRITE_MEASURING_MODE_NATURAL; - case TextFormattingMode::Display : return DWRITE_MEASURING_MODE_GDI_CLASSIC; - // We do not support Natural Metrics mode in WPF - default : throw gcnew System::InvalidOperationException(); - } - } - - TextFormattingMode DWriteTypeConverter::Convert(DWRITE_MEASURING_MODE dwriteMeasuringMode) - { - switch(dwriteMeasuringMode) - { - case DWRITE_MEASURING_MODE_NATURAL : return TextFormattingMode::Ideal; - case DWRITE_MEASURING_MODE_GDI_CLASSIC : return TextFormattingMode::Display; - // We do not support Natural Metrics mode in WPF - // However, the build system complained about not having an explicit case - // for DWRITE_TEXT_MEASURING_METHOD_USE_DISPLAY_NATURAL_METRICS - case DWRITE_MEASURING_MODE_GDI_NATURAL : throw gcnew System::InvalidOperationException(); - default : throw gcnew System::InvalidOperationException(); - } - } - }}}}//MS::Internal::Text::TextInterface diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.h index a872a43934f..955388c10f3 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.h +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteTypeConverter.h @@ -6,7 +6,6 @@ #define __DWRITETYPECONVERTER_H #include "Common.h" -#include "FactoryType.h" #include "FontWeight.h" #include "FontFaceType.h" #include "FontFileType.h" @@ -19,7 +18,6 @@ #include "DWriteGlyphOffset.h" #include "InformationalStringID.h" -using namespace System::Windows::Media; namespace MS { namespace Internal { namespace Text { namespace TextInterface { /// @@ -29,7 +27,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface { internal: - static DWRITE_FACTORY_TYPE Convert(FactoryType factoryType); static FontWeight Convert(DWRITE_FONT_WEIGHT fontWeight); static DWRITE_FONT_WEIGHT Convert(FontWeight fontWeight); static FontFileType Convert(DWRITE_FONT_FILE_TYPE dwriteFontFileType); @@ -48,8 +45,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface static System::Windows::Point Convert(DWRITE_GLYPH_OFFSET dwriteGlyphOffset); static DWRITE_INFORMATIONAL_STRING_ID Convert(InformationalStringID informationStringID); static InformationalStringID Convert(DWRITE_INFORMATIONAL_STRING_ID dwriteInformationStringID); - static DWRITE_MEASURING_MODE Convert(TextFormattingMode measuringMode); - static TextFormattingMode Convert(DWRITE_MEASURING_MODE dwriteMeasuringMode); }; }}}}//MS::Internal::Text::TextInterface diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.cpp b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.cpp index 03b56e99336..cab19fb338f 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.cpp +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.cpp @@ -12,10 +12,6 @@ using namespace MS::Internal::Text::TextInterface::Interfaces; #endif using namespace System::Threading; -typedef HRESULT (WINAPI *DWRITECREATEFACTORY)(DWRITE_FACTORY_TYPE factoryType, REFIID iid, IUnknown **factory); - -extern void *GetDWriteCreateFactoryFunctionPointer(); - namespace MS { namespace Internal { namespace Text { namespace TextInterface { HRESULT InternalFactory::CreateFontFile( diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h index 1b6da612b3f..c560b79a06d 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h @@ -6,7 +6,6 @@ #define __FACTORY_H #include "Common.h" -#include "FactoryType.h" #include "FontFile.h" #include "FontFace.h" #include "FontCollection.h" diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FactoryType.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FactoryType.h deleted file mode 100644 index ca6cec28650..00000000000 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FactoryType.h +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#ifndef __FACTORYTYPE_H -#define __FACTORYTYPE_H - -namespace MS { namespace Internal { namespace Text { namespace TextInterface -{ - /// - ///The type of the Factory. - /// - private enum class FactoryType - { - Shared, - Isolated - }; - -}}}}//MS::Internal::Text::TextInterface - -#endif //__FACTORYTYPE_H \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_FACTORY_TYPE.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_FACTORY_TYPE.cs new file mode 100644 index 00000000000..527d3241585 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_FACTORY_TYPE.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace MS.Internal.Interop.DWrite +{ + /// + /// Specifies the type of DirectWrite factory object. + /// DirectWrite factory contains internal state such as font loader registration and cached font data. + /// In most cases it is recommended to use the shared factory object, because it allows multiple components + /// that use DirectWrite to share internal DirectWrite state and reduce memory usage. + /// However, there are cases when it is desirable to reduce the impact of a component, + /// such as a plug-in from an untrusted source, on the rest of the process by sandboxing and isolating it + /// from the rest of the process components. In such cases, it is recommended to use an isolated factory for the sandboxed + /// component. + /// + internal enum DWRITE_FACTORY_TYPE + { + /// + /// Shared factory allow for re-use of cached font data across multiple in process components. + /// Such factories also take advantage of cross process font caching components for better performance. + /// + DWRITE_FACTORY_TYPE_SHARED, + + /// + /// Objects created from the isolated factory do not interact with internal DirectWrite state from other components. + /// + DWRITE_FACTORY_TYPE_ISOLATED + } +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_MEASURING_MODE.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_MEASURING_MODE.cs new file mode 100644 index 00000000000..7556c5dba2a --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/DWrite/DWRITE_MEASURING_MODE.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace MS.Internal.Interop.DWrite +{ + /// + /// The measuring method used for text layout. + /// + internal enum DWRITE_MEASURING_MODE + { + /// + /// Text is measured using glyph ideal metrics whose values are independent to the current display resolution. + /// + DWRITE_MEASURING_MODE_NATURAL, + + /// + /// Text is measured using glyph display compatible metrics whose values tuned for the current display resolution. + /// + DWRITE_MEASURING_MODE_GDI_CLASSIC, + + /// + // Text is measured using the same glyph display metrics as text measured by GDI using a font + // created with CLEARTYPE_NATURAL_QUALITY. + /// + DWRITE_MEASURING_MODE_GDI_NATURAL + } +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteTypeConverterEx.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteTypeConverterEx.cs new file mode 100644 index 00000000000..19e9c464ce5 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteTypeConverterEx.cs @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Windows.Media; +using MS.Internal.Interop.DWrite; + +namespace MS.Internal.Text.TextInterface +{ + /// + /// This class is used to convert data types back and forth between DWrite and DWriteWrapper. + /// + internal static class DWriteTypeConverterEx + { + internal static DWRITE_FACTORY_TYPE Convert(FactoryType factoryType) + { + switch (factoryType) + { + case FactoryType.Shared: + return DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED; + case FactoryType.Isolated: + return DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_ISOLATED; + default: + throw new InvalidOperationException(); + } + } + + internal static DWRITE_MEASURING_MODE Convert(TextFormattingMode measuringMode) + { + switch (measuringMode) + { + case TextFormattingMode.Ideal: + return DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL; + case TextFormattingMode.Display: + return DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_GDI_CLASSIC; + // We do not support Natural Metrics mode in WPF + default: + throw new InvalidOperationException(); + } + } + + internal static TextFormattingMode Convert(DWRITE_MEASURING_MODE dwriteMeasuringMode) + { + switch (dwriteMeasuringMode) + { + case DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL: + return TextFormattingMode.Ideal; + case DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_GDI_CLASSIC: + return TextFormattingMode.Display; + // We do not support Natural Metrics mode in WPF + // However, the build system complained about not having an explicit case + // for DWRITE_TEXT_MEASURING_METHOD_USE_DISPLAY_NATURAL_METRICS + case DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_GDI_NATURAL: + default: + throw new InvalidOperationException(); + } + } + } +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/Factory.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/Factory.cs index 9c1014f0f56..b34f9d95041 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/Factory.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/Factory.cs @@ -104,7 +104,7 @@ private void Initialize(FactoryType factoryType) delegate* unmanaged pfnDWriteCreateFactory = DWriteLoader.GetDWriteCreateFactoryFunctionPointer(); - int hr = pfnDWriteCreateFactory((int)DWriteTypeConverter.Convert(factoryType), &iid, &factory); + int hr = pfnDWriteCreateFactory((int)DWriteTypeConverterEx.Convert(factoryType), &iid, &factory); DWriteUtil.ConvertHresultToException(hr); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FactoryType.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FactoryType.cs new file mode 100644 index 00000000000..87624eb433b --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FactoryType.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace MS.Internal.Text.TextInterface +{ + /// + /// The type of the Factory. + /// + internal enum FactoryType + { + Shared, + Isolated + } +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj index 10a8cd48508..498245c06d6 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj @@ -229,8 +229,10 @@ + + @@ -275,8 +277,10 @@ + + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs index 74745540bcc..4218d2561f1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs @@ -1875,7 +1875,7 @@ private void CreateOnChannel(DUCE.Channel channel) command.GlyphCount = checked((UInt16)glyphCount); command.BidiLevel = checked((UInt16)_bidiLevel); command.pIDWriteFont = (UInt64)_glyphTypeface.GetDWriteFontAddRef; - command.DWriteTextMeasuringMethod = (UInt16)DWriteTypeConverter. + command.DWriteTextMeasuringMethod = (UInt16)DWriteTypeConverterEx. Convert(_textFormattingMode); // Advances