Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Arnab Animesh Das
rusttype
Commits
e049025d
Commit
e049025d
authored
Jul 18, 2020
by
Vitaliy
Committed by
Alex Butler
Jul 18, 2020
Browse files
Glyph lifetimes for Font::glyphs_for & Font::layout
parent
9d423252
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/font.rs
View file @
e049025d
...
...
@@ -137,7 +137,7 @@ impl<'font> Font<'font> {
/// points or glyph ids produced by the given iterator `itr`.
///
/// This is equivalent in behaviour to `itr.map(|c| font.glyph(c))`.
pub
fn
glyphs_for
<
I
:
Iterator
>
(
&
self
,
itr
:
I
)
->
GlyphIter
<
'
_
,
I
>
pub
fn
glyphs_for
<
'a
,
I
:
Iterator
>
(
&
'a
self
,
itr
:
I
)
->
GlyphIter
<
'
a
,
'font
,
I
>
where
I
::
Item
:
IntoGlyphId
,
{
...
...
@@ -177,25 +177,25 @@ impl<'font> Font<'font> {
/// # let (scale, start) = (Scale::uniform(0.0), point(0.0, 0.0));
/// # let font: Font = unimplemented!();
/// font.glyphs_for("Hello World!".chars())
/// .scan((None, 0.0), |
&mut (mut
last,
mut
x), g| {
/// .scan((None, 0.0), |
(
last, x), g| {
/// let g = g.scaled(scale);
/// if let Some(last) = last {
/// x += font.pair_kerning(scale, last, g.id());
///
*
x += font.pair_kerning(scale,
*
last, g.id());
/// }
/// let w = g.h_metrics().advance_width;
/// let next = g.positioned(start + vector(x, 0.0));
/// last = Some(next.id());
/// x += w;
/// let next = g.positioned(start + vector(
*
x, 0.0));
///
*
last = Some(next.id());
///
*
x += w;
/// Some(next)
/// })
/// # ;
/// ```
pub
fn
layout
<
'
f
,
's
>
(
&
'
f
self
,
pub
fn
layout
<
'
a
,
's
>
(
&
'
a
self
,
s
:
&
's
str
,
scale
:
Scale
,
start
:
Point
<
f32
>
,
)
->
LayoutIter
<
'
f
,
's
>
{
)
->
LayoutIter
<
'
a
,
'font
,
's
>
{
LayoutIter
{
font
:
self
,
chars
:
s
.chars
(),
...
...
src/gpu_cache.rs
View file @
e049025d
...
...
@@ -997,7 +997,7 @@ mod test {
let
font_data
=
include_bytes!
(
"../dev/fonts/wqy-microhei/WenQuanYiMicroHei.ttf"
);
let
font
=
Font
::
try_from_bytes
(
font_data
as
&
[
u8
])
.unwrap
();
let
mut
cache
=
Cache
::
builder
()
let
mut
cache
:
Cache
<
'static
>
=
Cache
::
builder
()
.dimensions
(
32
,
32
)
.scale_tolerance
(
0.1
)
.position_tolerance
(
0.1
)
...
...
src/lib.rs
View file @
e049025d
...
...
@@ -528,29 +528,29 @@ impl<G: Into<GlyphId>> IntoGlyphId for G {
}
#[derive(Clone)]
pub
struct
GlyphIter
<
'
b
,
I
:
Iterator
>
pub
struct
GlyphIter
<
'
a
,
'font
,
I
:
Iterator
>
where
I
::
Item
:
IntoGlyphId
,
{
font
:
&
'
b
Font
<
'
b
>
,
font
:
&
'
a
Font
<
'
font
>
,
itr
:
I
,
}
impl
<
'
b
,
I
>
Iterator
for
GlyphIter
<
'
b
,
I
>
impl
<
'
a
,
'font
,
I
>
Iterator
for
GlyphIter
<
'
a
,
'font
,
I
>
where
I
:
Iterator
,
I
::
Item
:
IntoGlyphId
,
{
type
Item
=
Glyph
<
'
b
>
;
type
Item
=
Glyph
<
'
font
>
;
fn
next
(
&
mut
self
)
->
Option
<
Glyph
<
'
b
>>
{
fn
next
(
&
mut
self
)
->
Option
<
Glyph
<
'
font
>>
{
self
.itr
.next
()
.map
(|
c
|
self
.font
.glyph
(
c
))
}
}
#[derive(Clone)]
pub
struct
LayoutIter
<
'font
,
's
>
{
font
:
&
'
font
Font
<
'font
>
,
pub
struct
LayoutIter
<
'a
,
'font
,
's
>
{
font
:
&
'
a
Font
<
'font
>
,
chars
:
core
::
str
::
Chars
<
's
>
,
caret
:
f32
,
scale
:
Scale
,
...
...
@@ -558,7 +558,7 @@ pub struct LayoutIter<'font, 's> {
last_glyph
:
Option
<
GlyphId
>
,
}
impl
<
'font
,
's
>
Iterator
for
LayoutIter
<
'font
,
's
>
{
impl
<
'a
,
'font
,
's
>
Iterator
for
LayoutIter
<
'a
,
'font
,
's
>
{
type
Item
=
PositionedGlyph
<
'font
>
;
fn
next
(
&
mut
self
)
->
Option
<
PositionedGlyph
<
'font
>>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment