summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/hints.cc2
-rw-r--r--src/lib/util.cc19
-rw-r--r--src/lib/util.h1
3 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/hints.cc b/src/lib/hints.cc
index d961b1a30..6238aa991 100644
--- a/src/lib/hints.cc
+++ b/src/lib/hints.cc
@@ -311,7 +311,7 @@ Hints::text (PlayerText text, TextType type, DCPTimePeriod period)
int lines = text.string.size();
BOOST_FOREACH (StringText i, text.string) {
- if (i.text().length() > CLOSED_CAPTION_LENGTH) {
+ if (utf8_strlen(i.text()) > CLOSED_CAPTION_LENGTH) {
++lines;
if (!_long_ccap) {
_long_ccap = true;
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 7472047e8..cd2d2e753 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -815,6 +815,25 @@ checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path pat
}
}
+size_t
+utf8_strlen (string s)
+{
+ size_t const len = s.length ();
+ int N = 0;
+ for (size_t i = 0; i < len; ++i) {
+ unsigned char c = s[i];
+ if ((c & 0xe0) == 0xc0) {
+ ++i;
+ } else if ((c & 0xf0) == 0xe0) {
+ i += 2;
+ } else if ((c & 0xf8) == 0xf0) {
+ i += 3;
+ }
+ ++N;
+ }
+ return N;
+}
+
#ifdef DCPOMATIC_VARIANT_SWAROOP
/* Make up a key from the machine UUID */
diff --git a/src/lib/util.h b/src/lib/util.h
index bdf2480fc..7c0eb4b6d 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -100,6 +100,7 @@ extern boost::shared_ptr<AudioBuffers> remap (boost::shared_ptr<const AudioBuffe
extern Eyes increment_eyes (Eyes e);
extern void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path);
extern void checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem::path path);
+extern size_t utf8_strlen (std::string s);
#ifdef DCPOMATIC_VARIANT_SWAROOP
extern boost::shared_ptr<dcp::CertificateChain> read_swaroop_chain (boost::filesystem::path path);
extern void write_swaroop_chain (boost::shared_ptr<const dcp::CertificateChain> chain, boost::filesystem::path output);