Skip to content

Commit 2d2b4c8

Browse files
author
bors-servo
authored
Auto merge of #7 - Eijebong:winapi, r=emilio
Bump winapi to 0.3 I had to drop all those `#[derive(Debug)]` because winapi types don't implement Debug anymore.
2 parents 3d37858 + ea7dcd6 commit 2d2b4c8

17 files changed

+194
-175
lines changed

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ name = "dwrote"
1212
[dependencies]
1313
libc = "0.2"
1414
lazy_static = "1"
15-
winapi = "0.2"
16-
kernel32-sys = "0.2"
17-
gdi32-sys = "0.2"
15+
winapi = { version = "0.3", features = ["dwrite", "winnt", "unknwnbase", "libloaderapi", "winnls"] }
1816
serde = "1.0"
1917
serde_derive = "1.0"

src/bitmap_render_target.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@ use std::cell::UnsafeCell;
77
use std::mem::{zeroed, size_of};
88

99
use comptr::ComPtr;
10-
use winapi;
11-
use gdi32;
10+
use winapi::um::dwrite::{DWRITE_GLYPH_RUN, DWRITE_GLYPH_OFFSET};
11+
use winapi::um::dwrite::IDWriteBitmapRenderTarget;
12+
use winapi::um::dcommon::{DWRITE_MEASURING_MODE};
13+
use winapi::um::wingdi::{BITMAP, OBJ_BITMAP, RGB, GetObjectW, GetCurrentObject};
14+
use winapi::shared::windef::{RECT, HDC};
15+
use winapi::ctypes::c_void;
1216
use super::{FontFace, RenderingParams};
1317

14-
#[derive(Debug)]
1518
pub struct BitmapRenderTarget {
16-
native: UnsafeCell<ComPtr<winapi::IDWriteBitmapRenderTarget>>,
19+
native: UnsafeCell<ComPtr<IDWriteBitmapRenderTarget>>,
1720
}
1821

1922
impl BitmapRenderTarget {
20-
pub fn take(native: ComPtr<winapi::IDWriteBitmapRenderTarget>) -> BitmapRenderTarget {
23+
pub fn take(native: ComPtr<IDWriteBitmapRenderTarget>) -> BitmapRenderTarget {
2124
BitmapRenderTarget {
2225
native: UnsafeCell::new(native),
2326
}
2427
}
2528

26-
pub unsafe fn as_ptr(&self) -> *mut winapi::IDWriteBitmapRenderTarget {
29+
pub unsafe fn as_ptr(&self) -> *mut IDWriteBitmapRenderTarget {
2730
(*self.native.get()).as_ptr()
2831
}
2932

@@ -34,7 +37,7 @@ impl BitmapRenderTarget {
3437
}
3538
}
3639

37-
pub fn get_memory_dc(&self) -> winapi::HDC {
40+
pub fn get_memory_dc(&self) -> HDC {
3841
unsafe {
3942
(*self.native.get()).GetMemoryDC()
4043
}
@@ -43,15 +46,15 @@ impl BitmapRenderTarget {
4346
pub fn draw_glyph_run(&self,
4447
baseline_origin_x: f32,
4548
baseline_origin_y: f32,
46-
measuring_mode: winapi::DWRITE_MEASURING_MODE,
49+
measuring_mode: DWRITE_MEASURING_MODE,
4750
font_face: &FontFace,
4851
em_size: f32,
4952
glyph_indices: &[u16],
5053
glyph_advances: &[f32],
51-
glyph_offsets: &[winapi::DWRITE_GLYPH_OFFSET],
54+
glyph_offsets: &[DWRITE_GLYPH_OFFSET],
5255
rendering_params: &RenderingParams,
5356
color: &(f32, f32, f32))
54-
-> winapi::RECT
57+
-> RECT
5558
{
5659
unsafe {
5760
assert!(glyph_indices.len() == glyph_advances.len());
@@ -61,7 +64,7 @@ impl BitmapRenderTarget {
6164
let g = (color.1 * 255.0) as u8;
6265
let b = (color.2 * 255.0) as u8;
6366

64-
let mut glyph_run: winapi::DWRITE_GLYPH_RUN = zeroed();
67+
let mut glyph_run: DWRITE_GLYPH_RUN = zeroed();
6568
glyph_run.fontFace = font_face.as_ptr();
6669
glyph_run.fontEmSize = em_size;
6770
glyph_run.glyphCount = glyph_indices.len() as u32;
@@ -71,13 +74,13 @@ impl BitmapRenderTarget {
7174
glyph_run.isSideways = 0;
7275
glyph_run.bidiLevel = 0;
7376

74-
let mut rect: winapi::RECT = zeroed();
77+
let mut rect: RECT = zeroed();
7578
let hr = (*self.native.get()).DrawGlyphRun(baseline_origin_x,
7679
baseline_origin_y,
7780
measuring_mode,
7881
&glyph_run,
7982
rendering_params.as_ptr(),
80-
winapi::RGB(r,g,b),
83+
RGB(r,g,b),
8184
&mut rect);
8285
assert!(hr == 0);
8386
rect
@@ -93,11 +96,11 @@ impl BitmapRenderTarget {
9396
// Now grossness to pull out the pixels
9497
unsafe {
9598
let memory_dc = self.get_memory_dc();
96-
let mut bitmap: winapi::BITMAP = zeroed();
97-
let ret = gdi32::GetObjectW(gdi32::GetCurrentObject(memory_dc, winapi::OBJ_BITMAP),
98-
size_of::<winapi::BITMAP>() as i32,
99-
&mut bitmap as *mut _ as *mut winapi::c_void);
100-
assert!(ret == size_of::<winapi::BITMAP>() as i32);
99+
let mut bitmap: BITMAP = zeroed();
100+
let ret = GetObjectW(GetCurrentObject(memory_dc, OBJ_BITMAP),
101+
size_of::<BITMAP>() as i32,
102+
&mut bitmap as *mut _ as *mut c_void);
103+
assert!(ret == size_of::<BITMAP>() as i32);
101104
assert!(bitmap.bmBitsPixel == 32);
102105

103106
let width = bitmap.bmWidth as usize;

src/com_helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ macro_rules! implement_iunknown {
2626
} else if guid_equals!(*riid, UuidOfIUnknown) {
2727
mem::transmute(This)
2828
} else {
29-
return $crate::winapi::E_NOINTERFACE;
29+
return $crate::winapi::shared::winerror::E_NOINTERFACE;
3030
};
3131

3232
(*This).AddRef();
@@ -67,7 +67,7 @@ macro_rules! implement_iunknown {
6767
} else if guid_equals!(*riid, UuidOfIUnknown) {
6868
mem::transmute(This)
6969
} else {
70-
return $crate::winapi::E_NOINTERFACE;
70+
return $crate::winapi::shared::winerror::E_NOINTERFACE;
7171
};
7272

7373
(*This).AddRef();

src/comptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use std::ops::{Deref, DerefMut};
66
use std::ptr;
7-
use winapi::{IUnknown, REFIID, S_OK, E_NOINTERFACE};
7+
use winapi::um::unknwnbase::IUnknown;
8+
use winapi::shared::guiddef::REFIID;
9+
use winapi::shared::winerror::{S_OK, E_NOINTERFACE};
810

911
#[derive(Debug)]
1012
pub struct ComPtr<T> {

src/font.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
use std::cell::UnsafeCell;
66

77
use comptr::ComPtr;
8-
use winapi;
8+
use winapi::um::dwrite::{IDWriteFontFace, IDWriteLocalizedStrings, IDWriteFont};
9+
use winapi::um::dwrite::IDWriteFontFamily;
910
use std::mem;
1011

1112
use super::*;
1213
use helpers::*;
1314

14-
#[derive(Debug)]
1515
pub struct Font {
16-
native: UnsafeCell<ComPtr<winapi::IDWriteFont>>,
16+
native: UnsafeCell<ComPtr<IDWriteFont>>,
1717
}
1818

1919
impl Font {
20-
pub fn take(native: ComPtr<winapi::IDWriteFont>) -> Font {
20+
pub fn take(native: ComPtr<IDWriteFont>) -> Font {
2121
Font {
2222
native: UnsafeCell::new(native),
2323
}
2424
}
2525

26-
pub unsafe fn as_ptr(&self) -> *mut winapi::IDWriteFont {
26+
pub unsafe fn as_ptr(&self) -> *mut IDWriteFont {
2727
(*self.native.get()).as_ptr()
2828
}
2929

@@ -38,25 +38,25 @@ impl Font {
3838

3939
pub fn stretch(&self) -> FontStretch {
4040
unsafe {
41-
mem::transmute::<u32, FontStretch>((*self.native.get()).GetStretch().0)
41+
mem::transmute::<u32, FontStretch>((*self.native.get()).GetStretch())
4242
}
4343
}
4444

4545
pub fn style(&self) -> FontStyle {
4646
unsafe {
47-
mem::transmute::<u32, FontStyle>((*self.native.get()).GetStyle().0)
47+
mem::transmute::<u32, FontStyle>((*self.native.get()).GetStyle())
4848
}
4949
}
5050

5151
pub fn weight(&self) -> FontWeight {
5252
unsafe {
53-
mem::transmute::<u32, FontWeight>((*self.native.get()).GetWeight().0)
53+
mem::transmute::<u32, FontWeight>((*self.native.get()).GetWeight())
5454
}
5555
}
5656

5757
pub fn family_name(&self) -> String {
5858
unsafe {
59-
let mut family: ComPtr<winapi::IDWriteFontFamily> = ComPtr::new();
59+
let mut family: ComPtr<IDWriteFontFamily> = ComPtr::new();
6060
let hr = (*self.native.get()).GetFontFamily(family.getter_addrefs());
6161
assert!(hr == 0);
6262

@@ -66,7 +66,7 @@ impl Font {
6666

6767
pub fn face_name(&self) -> String {
6868
unsafe {
69-
let mut names: ComPtr<winapi::IDWriteLocalizedStrings> = ComPtr::new();
69+
let mut names: ComPtr<IDWriteLocalizedStrings> = ComPtr::new();
7070
let hr = (*self.native.get()).GetFaceNames(names.getter_addrefs());
7171
assert!(hr == 0);
7272

@@ -78,7 +78,7 @@ impl Font {
7878
// FIXME create_font_face should cache the FontFace and return it,
7979
// there's a 1:1 relationship
8080
unsafe {
81-
let mut face: ComPtr<winapi::IDWriteFontFace> = ComPtr::new();
81+
let mut face: ComPtr<IDWriteFontFace> = ComPtr::new();
8282
let hr = (*self.native.get()).CreateFontFace(face.getter_addrefs());
8383
assert!(hr == 0);
8484
FontFace::take(face)

src/font_collection.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use comptr::ComPtr;
6-
use winapi;
7-
use winapi::FALSE;
6+
use winapi::um::dwrite::{IDWriteFontFamily, IDWriteFont, IDWriteFontCollection};
7+
use winapi::shared::minwindef::{BOOL, FALSE};
88
use std::cell::UnsafeCell;
99

1010
use super::{DWriteFactory, FontFamily, Font, FontFace, FontDescriptor};
1111
use helpers::*;
1212

13-
#[derive(Debug)]
1413
pub struct FontCollectionFamilyIterator {
15-
collection: ComPtr<winapi::IDWriteFontCollection>,
14+
collection: ComPtr<IDWriteFontCollection>,
1615
curr: u32,
1716
count: u32,
1817
}
@@ -25,7 +24,7 @@ impl Iterator for FontCollectionFamilyIterator {
2524
}
2625

2726
unsafe {
28-
let mut family: ComPtr<winapi::IDWriteFontFamily> = ComPtr::new();
27+
let mut family: ComPtr<IDWriteFontFamily> = ComPtr::new();
2928
let hr = self.collection.GetFontFamily(self.curr, family.getter_addrefs());
3029
assert!(hr == 0);
3130
self.curr += 1;
@@ -35,13 +34,13 @@ impl Iterator for FontCollectionFamilyIterator {
3534
}
3635

3736
pub struct FontCollection {
38-
native: UnsafeCell<ComPtr<winapi::IDWriteFontCollection>>,
37+
native: UnsafeCell<ComPtr<IDWriteFontCollection>>,
3938
}
4039

4140
impl FontCollection {
4241
pub fn system() -> FontCollection {
4342
unsafe {
44-
let mut native: ComPtr<winapi::IDWriteFontCollection> = ComPtr::new();
43+
let mut native: ComPtr<IDWriteFontCollection> = ComPtr::new();
4544
let hr = (*DWriteFactory()).GetSystemFontCollection(native.getter_addrefs(), FALSE);
4645
assert!(hr == 0);
4746

@@ -51,17 +50,16 @@ impl FontCollection {
5150
}
5251
}
5352

54-
pub fn take(native: ComPtr<winapi::IDWriteFontCollection>) -> FontCollection {
53+
pub fn take(native: ComPtr<IDWriteFontCollection>) -> FontCollection {
5554
FontCollection {
5655
native: UnsafeCell::new(native)
5756
}
5857
}
5958

60-
pub unsafe fn as_ptr(&self) -> *mut winapi::IDWriteFontCollection {
59+
pub unsafe fn as_ptr(&self) -> *mut IDWriteFontCollection {
6160
(*self.native.get()).as_ptr()
6261
}
6362

64-
6563
pub fn families_iter(&self) -> FontCollectionFamilyIterator {
6664
unsafe {
6765
FontCollectionFamilyIterator {
@@ -80,7 +78,7 @@ impl FontCollection {
8078

8179
pub fn get_font_family(&self, index: u32) -> FontFamily {
8280
unsafe {
83-
let mut family: ComPtr<winapi::IDWriteFontFamily> = ComPtr::new();
81+
let mut family: ComPtr<IDWriteFontFamily> = ComPtr::new();
8482
let hr = (*self.native.get()).GetFontFamily(index, family.getter_addrefs());
8583
assert!(hr == 0);
8684
FontFamily::take(family)
@@ -106,7 +104,7 @@ impl FontCollection {
106104

107105
pub fn get_font_from_face(&self, face: &FontFace) -> Option<Font> {
108106
unsafe {
109-
let mut font: ComPtr<winapi::IDWriteFont> = ComPtr::new();
107+
let mut font: ComPtr<IDWriteFont> = ComPtr::new();
110108
let hr = (*self.native.get()).GetFontFromFontFace(face.as_ptr(), font.getter_addrefs());
111109
if hr != 0 {
112110
return None;
@@ -118,14 +116,14 @@ impl FontCollection {
118116
pub fn get_font_family_by_name(&self, family_name: &str) -> Option<FontFamily> {
119117
unsafe {
120118
let mut index: u32 = 0;
121-
let mut exists: winapi::BOOL = winapi::FALSE;
119+
let mut exists: BOOL = FALSE;
122120
let hr = (*self.native.get()).FindFamilyName(family_name.to_wide_null().as_ptr(), &mut index, &mut exists);
123121
assert!(hr == 0);
124-
if exists == winapi::FALSE {
122+
if exists == FALSE {
125123
return None;
126124
}
127125

128-
let mut family: ComPtr<winapi::IDWriteFontFamily> = ComPtr::new();
126+
let mut family: ComPtr<IDWriteFontFamily> = ComPtr::new();
129127
let hr = (*self.native.get()).GetFontFamily(index, family.getter_addrefs());
130128
assert!(hr == 0);
131129

0 commit comments

Comments
 (0)