Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1a83e05

Browse files
committed
Replace std::to_chars with plain snprintf
The former is not available on the macOS deployment target we use forwheels. We could revert back to `PyOS_snprintf`, but C++11 contains`snprintf`, and it seems to guarantee the same things.
1 parent35458ae commit1a83e05

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

‎src/ft2font.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -*- mode: c++; c-basic-offset: 4 -*-*/
22

33
#include<algorithm>
4-
#include<charconv>
4+
#include<cstdio>
55
#include<iterator>
66
#include<set>
77
#include<sstream>
@@ -727,13 +727,20 @@ void FT2Font::get_glyph_name(unsigned int glyph_number, std::string &buffer,
727727
if (!FT_HAS_GLYPH_NAMES(face)) {
728728
/* Note that this generated name must match the name that
729729
is generated by ttconv in ttfont_CharStrings_getname.*/
730-
buffer.replace(0,3,"uni");
731-
std::to_chars(buffer.data() +3, buffer.data() + buffer.size(),
732-
glyph_number,16);
730+
auto len =snprintf(buffer.data(), buffer.size(),"uni%08x", glyph_number);
731+
if (len >=0) {
732+
buffer.resize(len);
733+
}else {
734+
throwstd::runtime_error("Failed to convert glyph to standard name");
735+
}
733736
}else {
734737
if (FT_Error error =FT_Get_Glyph_Name(face, glyph_number, buffer.data(), buffer.size())) {
735738
throw_ft_error("Could not get glyph names", error);
736739
}
740+
auto len = buffer.find('\0');
741+
if (len != buffer.npos) {
742+
buffer.resize(len);
743+
}
737744
}
738745
}
739746

‎src/ft2font_wrapper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@ PyFT2Font_get_glyph_name(PyFT2Font *self, unsigned int glyph_number)
486486

487487
buffer.resize(128);
488488
self->x->get_glyph_name(glyph_number, buffer, fallback);
489-
// pybind11 uses the entire string's size(), so trim all the NULLs off the end.
490-
auto len = buffer.find('\0');
491-
if (len != buffer.npos) {
492-
buffer.resize(len);
493-
}
494489
return buffer;
495490
}
496491

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp