3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 #include "Direct3D10Exception.h"
\r
29 #include "Device10.h"
\r
31 #include "FontDescription10.h"
\r
32 #include "Sprite10.h"
\r
34 using namespace System;
\r
38 namespace Direct3D10
\r
40 Font::Font( Device^ device, FontDescription description )
\r
42 Construct( Build( device, description.Height, description.Width, description.Weight, description.MipLevels, description.IsItalic, description.CharacterSet, description.Precision, description.Quality, description.PitchAndFamily, description.FaceName ) );
\r
45 Font::Font( Device^ device, int height, String^ faceName )
\r
47 Construct( Build( device, height, 0, FontWeight::Normal, 1, false, FontCharacterSet::Default, FontPrecision::Default, FontQuality::Default, FontPitchAndFamily::Default, faceName ) );
\r
50 Font::Font( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool isItalic, FontCharacterSet characterSet, FontPrecision precision, FontQuality quality, FontPitchAndFamily pitchAndFamily, String^ faceName )
\r
52 Construct( Build( device, height, width, weight, mipLevels, isItalic, characterSet, precision, quality, pitchAndFamily, faceName ) );
\r
55 ID3DX10Font* Font::Build( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool isItalic, FontCharacterSet characterSet, FontPrecision precision, FontQuality quality, FontPitchAndFamily pitchAndFamily, String^ faceName )
\r
57 ID3DX10Font* font = 0;
\r
58 pin_ptr<const wchar_t> pinned_name = PtrToStringChars( faceName );
\r
59 if( RECORD_D3D10( D3DX10CreateFont( device->InternalPointer, height, width, static_cast<UINT>( weight ), mipLevels, isItalic, static_cast<UINT>( characterSet ), static_cast<UINT>( precision ), static_cast< UINT>( quality ), static_cast<UINT>( pitchAndFamily ), pinned_name, &font ) ).IsFailure )
\r
60 throw gcnew Direct3D10Exception( Result::Last );
\r
65 FontDescription Font::Description::get()
\r
67 D3DX10_FONT_DESC nativeDescription;
\r
68 if( RECORD_D3D10( InternalPointer->GetDesc( &nativeDescription ) ).IsFailure )
\r
69 return FontDescription();
\r
71 return FontDescription( nativeDescription );
\r
74 int Font::Draw( Sprite^ sprite, String^ text, Drawing::Rectangle rect, FontDrawFlags flags, Color4 color )
\r
76 ID3DX10Sprite* nativeSprite = sprite == nullptr ? 0 : sprite->InternalPointer;
\r
77 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );
\r
78 RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };
\r
80 int result = InternalPointer->DrawTextW( nativeSprite, pinned_text, text->Length, &nativeRect,
\r
81 static_cast<DWORD>( flags ), color.ToUnmanaged() );
\r
86 Drawing::Rectangle Font::Measure( Sprite^ sprite, String^ text, Drawing::Rectangle rect, FontDrawFlags flags )
\r
88 ID3DX10Sprite* nativeSprite = sprite == nullptr ? 0 : sprite->InternalPointer;
\r
89 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );
\r
90 RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };
\r
91 InternalPointer->DrawTextW( nativeSprite, pinned_text, text->Length, &nativeRect, static_cast<DWORD>( flags ) | DT_CALCRECT, 0xFFFFFFFF );
\r
93 return Drawing::Rectangle( nativeRect.left, nativeRect.top, nativeRect.right - nativeRect.left, nativeRect.bottom - nativeRect.top );
\r
96 Result Font::PreloadCharacters( int first, int last )
\r
98 return RECORD_D3D10( InternalPointer->PreloadCharacters( first, last ) );
\r
101 Result Font::PreloadGlyphs( int first, int last )
\r
103 return RECORD_D3D10( InternalPointer->PreloadGlyphs( first, last ) );
\r
106 Result Font::PreloadText( String^ text )
\r
108 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );
\r
109 return RECORD_D3D10( InternalPointer->PreloadText( pinned_text, text->Length ) );
\r