Skip to content

Commit 2f19ebd

Browse files
committed
Use range-based for loops in extensions
1 parent 2d6d2a8 commit 2f19ebd

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/_c_internal_utils.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,16 @@ mpl_SetProcessDpiAwareness_max(void)
159159
SetProcessDpiAwarenessContext_t SetProcessDpiAwarenessContextPtr =
160160
(SetProcessDpiAwarenessContext_t)GetProcAddress(
161161
user32, "SetProcessDpiAwarenessContext");
162-
DPI_AWARENESS_CONTEXT ctxs[3] = {
163-
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, // Win10 Creators Update
164-
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, // Win10
165-
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE}; // Win10
166162
if (IsValidDpiAwarenessContextPtr != NULL
167163
&& SetProcessDpiAwarenessContextPtr != NULL) {
168-
for (size_t i = 0; i < sizeof(ctxs) / sizeof(DPI_AWARENESS_CONTEXT); ++i) {
169-
if (IsValidDpiAwarenessContextPtr(ctxs[i])) {
170-
SetProcessDpiAwarenessContextPtr(ctxs[i]);
164+
for (auto ctx : {
165+
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, // Win10 Creators Update
166+
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, // Win10
167+
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE, // Win10
168+
})
169+
{
170+
if (IsValidDpiAwarenessContextPtr(ctx)) {
171+
SetProcessDpiAwarenessContextPtr(ctx);
171172
break;
172173
}
173174
}

src/ft2font.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ FT2Font::FT2Font(FT_Open_Args &open_args,
293293

294294
FT2Font::~FT2Font()
295295
{
296-
for (size_t i = 0; i < glyphs.size(); i++) {
297-
FT_Done_Glyph(glyphs[i]);
296+
for (auto& glyph : glyphs) {
297+
FT_Done_Glyph(glyph);
298298
}
299299

300300
if (face) {
@@ -308,16 +308,16 @@ void FT2Font::clear()
308308
bbox.xMin = bbox.yMin = bbox.xMax = bbox.yMax = 0;
309309
advance = 0;
310310

311-
for (size_t i = 0; i < glyphs.size(); i++) {
312-
FT_Done_Glyph(glyphs[i]);
311+
for (auto& glyph : glyphs) {
312+
FT_Done_Glyph(glyph);
313313
}
314314

315315
glyphs.clear();
316316
glyph_to_font.clear();
317317
char_to_font.clear();
318318

319-
for (size_t i = 0; i < fallbacks.size(); i++) {
320-
fallbacks[i]->clear();
319+
for (auto& font : fallbacks) {
320+
font->clear();
321321
}
322322
}
323323

@@ -331,8 +331,8 @@ void FT2Font::set_size(double ptsize, double dpi)
331331
FT_Matrix transform = { 65536 / hinting_factor, 0, 0, 65536 };
332332
FT_Set_Transform(face, &transform, 0);
333333

334-
for (size_t i = 0; i < fallbacks.size(); i++) {
335-
fallbacks[i]->set_size(ptsize, dpi);
334+
for (auto& font : fallbacks) {
335+
font->set_size(ptsize, dpi);
336336
}
337337
}
338338

@@ -391,8 +391,8 @@ int FT2Font::get_kerning(FT_UInt left, FT_UInt right, FT_UInt mode, FT_Vector &d
391391
void FT2Font::set_kerning_factor(int factor)
392392
{
393393
kerning_factor = factor;
394-
for (size_t i = 0; i < fallbacks.size(); i++) {
395-
fallbacks[i]->set_kerning_factor(factor);
394+
for (auto& font : fallbacks) {
395+
font->set_kerning_factor(factor);
396396
}
397397
}
398398

@@ -451,7 +451,7 @@ void FT2Font::set_text(
451451
}
452452

453453
// extract glyph image and store it in our table
454-
FT_Glyph &thisGlyph = glyphs[glyphs.size() - 1];
454+
FT_Glyph &thisGlyph = glyphs.back();
455455

456456
last_advance = ft_object_with_glyph->get_face()->glyph->advance.x;
457457
FT_Glyph_Transform(thisGlyph, 0, &pen);
@@ -592,8 +592,8 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
592592
return true;
593593
}
594594
else {
595-
for (size_t i = 0; i < fallbacks.size(); ++i) {
596-
bool was_found = fallbacks[i]->load_char_with_fallback(
595+
for (auto& font : fallbacks) {
596+
bool was_found = font->load_char_with_fallback(
597597
ft_object_with_glyph, final_glyph_index, parent_glyphs,
598598
parent_char_to_font, parent_glyph_to_font, charcode, flags,
599599
charcode_error, glyph_error, glyph_seen_fonts, override);
@@ -672,14 +672,14 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
672672

673673
image.resize(width, height);
674674

675-
for (size_t n = 0; n < glyphs.size(); n++) {
675+
for (auto& glyph : glyphs) {
676676
FT_Error error = FT_Glyph_To_Bitmap(
677-
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
677+
&glyph, antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
678678
if (error) {
679679
throw_ft_error("Could not convert glyph to bitmap", error);
680680
}
681681

682-
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
682+
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
683683
// now, draw to our target surface (convert position)
684684

685685
// bitmap left and top in pixel, string bbox in subpixel

0 commit comments

Comments
 (0)