Merge branch 'cpp-11' into crashlog_improvements
# Conflicts: # Makefile.src.in # projects/determineversion.vbs # source.list # src/crashlog.cpp # src/misc.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/rev.h # src/thread/thread.h # src/thread/thread_morphos.cpp # src/thread/thread_none.cpp # src/thread/thread_os2.cpp # src/thread/thread_pthread.cpp # src/thread/thread_win32.cpp
This commit is contained in:
@@ -52,7 +52,7 @@ class CrashLogOSX : public CrashLog {
|
||||
char filename_save[MAX_PATH]; ///< Path of crash.sav
|
||||
char filename_screenshot[MAX_PATH]; ///< Path of crash.(png|bmp|pcx)
|
||||
|
||||
/* virtual */ char *LogOSVersion(char *buffer, const char *last) const
|
||||
char *LogOSVersion(char *buffer, const char *last) const override
|
||||
{
|
||||
int ver_maj, ver_min, ver_bug;
|
||||
GetMacOSVersion(&ver_maj, &ver_min, &ver_bug);
|
||||
@@ -71,7 +71,7 @@ class CrashLogOSX : public CrashLog {
|
||||
);
|
||||
}
|
||||
|
||||
/* virtual */ char *LogError(char *buffer, const char *last, const char *message) const
|
||||
char *LogError(char *buffer, const char *last, const char *message) const override
|
||||
{
|
||||
return buffer + seprintf(buffer, last,
|
||||
"Crash reason:\n"
|
||||
@@ -83,7 +83,7 @@ class CrashLogOSX : public CrashLog {
|
||||
);
|
||||
}
|
||||
|
||||
/* virtual */ char *LogStacktrace(char *buffer, const char *last) const
|
||||
char *LogStacktrace(char *buffer, const char *last) const override
|
||||
{
|
||||
/* As backtrace() is only implemented in 10.5 or later,
|
||||
* we're rolling our own here. Mostly based on
|
||||
|
||||
@@ -206,23 +206,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
}
|
||||
#endif
|
||||
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
uint count = 1;
|
||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||
if (MacOSVersionIsAtLeast(10, 5, 0)) {
|
||||
count = (uint)[ [ NSProcessInfo processInfo ] activeProcessorCount ];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
|
||||
count = MPProcessorsScheduled();
|
||||
#endif
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a font is a monospace font.
|
||||
* @param name Name of the font.
|
||||
|
||||
450
src/os/macosx/string_osx.cpp
Normal file
450
src/os/macosx/string_osx.cpp
Normal file
@@ -0,0 +1,450 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file string_osx.cpp Functions related to localized text support on OSX. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "string_osx.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../table/control_codes.h"
|
||||
#include "../../fontcache.h"
|
||||
#include "macos.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
|
||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||
/** Cached current locale. */
|
||||
static CFLocaleRef _osx_locale = NULL;
|
||||
/** CoreText cache for font information, cleared when OTTD changes fonts. */
|
||||
static CTFontRef _font_cache[FS_END];
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for doing layouts with CoreText.
|
||||
*/
|
||||
class CoreTextParagraphLayout : public ParagraphLayouter {
|
||||
private:
|
||||
const CoreTextParagraphLayoutFactory::CharType *text_buffer;
|
||||
ptrdiff_t length;
|
||||
const FontMap& font_map;
|
||||
|
||||
CTTypesetterRef typesetter;
|
||||
|
||||
CFIndex cur_offset = 0; ///< Offset from the start of the current run from where to output.
|
||||
|
||||
public:
|
||||
/** Visual run contains data about the bit of text with the same font. */
|
||||
class CoreTextVisualRun : public ParagraphLayouter::VisualRun {
|
||||
private:
|
||||
std::vector<GlyphID> glyphs;
|
||||
std::vector<float> positions;
|
||||
std::vector<int> glyph_to_char;
|
||||
|
||||
int total_advance = 0;
|
||||
Font *font;
|
||||
|
||||
public:
|
||||
CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff);
|
||||
|
||||
virtual const GlyphID *GetGlyphs() const { return &this->glyphs[0]; }
|
||||
virtual const float *GetPositions() const { return &this->positions[0]; }
|
||||
virtual const int *GetGlyphToCharMap() const { return &this->glyph_to_char[0]; }
|
||||
|
||||
virtual const Font *GetFont() const { return this->font; }
|
||||
virtual int GetLeading() const { return this->font->fc->GetHeight(); }
|
||||
virtual int GetGlyphCount() const { return (int)this->glyphs.size(); }
|
||||
int GetAdvance() const { return this->total_advance; }
|
||||
};
|
||||
|
||||
/** A single line worth of VisualRuns. */
|
||||
class CoreTextLine : public AutoDeleteSmallVector<CoreTextVisualRun *>, public ParagraphLayouter::Line {
|
||||
public:
|
||||
CoreTextLine(CTLineRef line, const FontMap &fontMapping, const CoreTextParagraphLayoutFactory::CharType *buff)
|
||||
{
|
||||
CFArrayRef runs = CTLineGetGlyphRuns(line);
|
||||
for (CFIndex i = 0; i < CFArrayGetCount(runs); i++) {
|
||||
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, i);
|
||||
|
||||
/* Extract font information for this run. */
|
||||
CFRange chars = CTRunGetStringRange(run);
|
||||
auto map = fontMapping.begin();
|
||||
while (map < fontMapping.end() - 1 && map->first <= chars.location) map++;
|
||||
|
||||
this->push_back(new CoreTextVisualRun(run, map->second, buff));
|
||||
}
|
||||
CFRelease(line);
|
||||
}
|
||||
|
||||
virtual int GetLeading() const;
|
||||
virtual int GetWidth() const;
|
||||
virtual int CountRuns() const { return this->size(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(WChar c) const
|
||||
{
|
||||
/* CoreText uses UTF-16 internally which means we need to account for surrogate pairs. */
|
||||
return c >= 0x010000U ? 2 : 1;
|
||||
}
|
||||
};
|
||||
|
||||
CoreTextParagraphLayout(CTTypesetterRef typesetter, const CoreTextParagraphLayoutFactory::CharType *buffer, ptrdiff_t len, const FontMap &fontMapping) : text_buffer(buffer), length(len), font_map(fontMapping), typesetter(typesetter)
|
||||
{
|
||||
this->Reflow();
|
||||
}
|
||||
|
||||
virtual ~CoreTextParagraphLayout()
|
||||
{
|
||||
CFRelease(this->typesetter);
|
||||
}
|
||||
|
||||
virtual void Reflow()
|
||||
{
|
||||
this->cur_offset = 0;
|
||||
}
|
||||
|
||||
virtual const Line *NextLine(int max_width);
|
||||
};
|
||||
|
||||
|
||||
/** Get the width of an encoded sprite font character. */
|
||||
static CGFloat SpriteFontGetWidth(void *ref_con)
|
||||
{
|
||||
FontSize fs = (FontSize)((size_t)ref_con >> 24);
|
||||
WChar c = (WChar)((size_t)ref_con & 0xFFFFFF);
|
||||
|
||||
return GetGlyphWidth(fs, c);
|
||||
}
|
||||
|
||||
static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||
kCTRunDelegateCurrentVersion, NULL, NULL, NULL,
|
||||
&SpriteFontGetWidth
|
||||
};
|
||||
|
||||
/* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
||||
{
|
||||
if (!MacOSVersionIsAtLeast(10, 5, 0)) return NULL;
|
||||
|
||||
/* Can't layout an empty string. */
|
||||
ptrdiff_t length = buff_end - buff;
|
||||
if (length == 0) return NULL;
|
||||
|
||||
/* Can't layout our in-built sprite fonts. */
|
||||
for (const auto &i : fontMapping) {
|
||||
if (i.second->fc->IsBuiltInFont()) return NULL;
|
||||
}
|
||||
|
||||
/* Make attributed string with embedded font information. */
|
||||
CFMutableAttributedStringRef str = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
|
||||
CFAttributedStringBeginEditing(str);
|
||||
|
||||
CFStringRef base = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, buff, length, kCFAllocatorNull);
|
||||
CFAttributedStringReplaceString(str, CFRangeMake(0, 0), base);
|
||||
CFRelease(base);
|
||||
|
||||
/* Apply font and colour ranges to our string. This is important to make sure
|
||||
* that we get proper glyph boundaries on style changes. */
|
||||
int last = 0;
|
||||
for (const auto &i : fontMapping) {
|
||||
if (i.first - last == 0) continue;
|
||||
|
||||
if (_font_cache[i.second->fc->GetSize()] == NULL) {
|
||||
/* Cache font information. */
|
||||
CFStringRef font_name = CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8);
|
||||
_font_cache[i.second->fc->GetSize()] = CTFontCreateWithName(font_name, i.second->fc->GetFontSize(), NULL);
|
||||
CFRelease(font_name);
|
||||
}
|
||||
CFAttributedStringSetAttribute(str, CFRangeMake(last, i.first - last), kCTFontAttributeName, _font_cache[i.second->fc->GetSize()]);
|
||||
|
||||
CGColorRef color = CGColorCreateGenericGray((uint8)i.second->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
|
||||
CFAttributedStringSetAttribute(str, CFRangeMake(last, i.first - last), kCTForegroundColorAttributeName, color);
|
||||
CGColorRelease(color);
|
||||
|
||||
/* Install a size callback for our special sprite glyphs. */
|
||||
for (ssize_t c = last; c < i.first; c++) {
|
||||
if (buff[c] >= SCC_SPRITE_START && buff[c] <= SCC_SPRITE_END) {
|
||||
CTRunDelegateRef del = CTRunDelegateCreate(&_sprite_font_callback, (void *)(size_t)(buff[c] | (i.second->fc->GetSize() << 24)));
|
||||
CFAttributedStringSetAttribute(str, CFRangeMake(c, 1), kCTRunDelegateAttributeName, del);
|
||||
CFRelease(del);
|
||||
}
|
||||
}
|
||||
|
||||
last = i.first;
|
||||
}
|
||||
CFAttributedStringEndEditing(str);
|
||||
|
||||
/* Create and return typesetter for the string. */
|
||||
CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString(str);
|
||||
CFRelease(str);
|
||||
|
||||
return typesetter != NULL ? new CoreTextParagraphLayout(typesetter, buff, length, fontMapping) : NULL;
|
||||
}
|
||||
|
||||
/* virtual */ const CoreTextParagraphLayout::Line *CoreTextParagraphLayout::NextLine(int max_width)
|
||||
{
|
||||
if (this->cur_offset >= this->length) return NULL;
|
||||
|
||||
/* Get line break position, trying word breaking first and breaking somewhere if that doesn't work. */
|
||||
CFIndex len = CTTypesetterSuggestLineBreak(this->typesetter, this->cur_offset, max_width);
|
||||
if (len <= 0) len = CTTypesetterSuggestClusterBreak(this->typesetter, this->cur_offset, max_width);
|
||||
|
||||
/* Create line. */
|
||||
CTLineRef line = CTTypesetterCreateLine(this->typesetter, CFRangeMake(this->cur_offset, len));
|
||||
this->cur_offset += len;
|
||||
|
||||
return line != NULL ? new CoreTextLine(line, this->font_map, this->text_buffer) : NULL;
|
||||
}
|
||||
|
||||
CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font)
|
||||
{
|
||||
this->glyphs.resize(CTRunGetGlyphCount(run));
|
||||
|
||||
/* Query map of glyphs to source string index. */
|
||||
CFIndex map[this->glyphs.size()];
|
||||
CTRunGetStringIndices(run, CFRangeMake(0, 0), map);
|
||||
|
||||
this->glyph_to_char.resize(this->glyphs.size());
|
||||
for (size_t i = 0; i < this->glyph_to_char.size(); i++) this->glyph_to_char[i] = (int)map[i];
|
||||
|
||||
CGPoint pts[this->glyphs.size()];
|
||||
CTRunGetPositions(run, CFRangeMake(0, 0), pts);
|
||||
this->positions.resize(this->glyphs.size() * 2 + 2);
|
||||
|
||||
/* Convert glyph array to our data type. At the same time, substitute
|
||||
* the proper glyphs for our private sprite glyphs. */
|
||||
CGGlyph gl[this->glyphs.size()];
|
||||
CTRunGetGlyphs(run, CFRangeMake(0, 0), gl);
|
||||
for (size_t i = 0; i < this->glyphs.size(); i++) {
|
||||
if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END) {
|
||||
this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]);
|
||||
this->positions[i * 2 + 0] = pts[i].x;
|
||||
this->positions[i * 2 + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline.
|
||||
} else {
|
||||
this->glyphs[i] = gl[i];
|
||||
this->positions[i * 2 + 0] = pts[i].x;
|
||||
this->positions[i * 2 + 1] = pts[i].y;
|
||||
}
|
||||
}
|
||||
this->total_advance = (int)CTRunGetTypographicBounds(run, CFRangeMake(0, 0), NULL, NULL, NULL);
|
||||
this->positions[this->glyphs.size() * 2] = this->positions[0] + this->total_advance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the line.
|
||||
* @return The maximum height of the line.
|
||||
*/
|
||||
int CoreTextParagraphLayout::CoreTextLine::GetLeading() const
|
||||
{
|
||||
int leading = 0;
|
||||
for (const CoreTextVisualRun * const &run : *this) {
|
||||
leading = max(leading, run->GetLeading());
|
||||
}
|
||||
|
||||
return leading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of this line.
|
||||
* @return The width of the line.
|
||||
*/
|
||||
int CoreTextParagraphLayout::CoreTextLine::GetWidth() const
|
||||
{
|
||||
if (this->size() == 0) return 0;
|
||||
|
||||
int total_width = 0;
|
||||
for (const CoreTextVisualRun * const &run : *this) {
|
||||
total_width += run->GetAdvance();
|
||||
}
|
||||
|
||||
return total_width;
|
||||
}
|
||||
|
||||
|
||||
/** Delete CoreText font reference for a specific font size. */
|
||||
void MacOSResetScriptCache(FontSize size)
|
||||
{
|
||||
if (_font_cache[size] != NULL) {
|
||||
CFRelease(_font_cache[size]);
|
||||
_font_cache[size] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/** Store current language locale as a CoreFounation locale. */
|
||||
void MacOSSetCurrentLocaleName(const char *iso_code)
|
||||
{
|
||||
if (!MacOSVersionIsAtLeast(10, 5, 0)) return;
|
||||
|
||||
if (_osx_locale != NULL) CFRelease(_osx_locale);
|
||||
|
||||
CFStringRef iso = CFStringCreateWithCString(kCFAllocatorNull, iso_code, kCFStringEncodingUTF8);
|
||||
_osx_locale = CFLocaleCreate(kCFAllocatorDefault, iso);
|
||||
CFRelease(iso);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two strings using case insensitive natural sort.
|
||||
*
|
||||
* @param s1 First string to compare.
|
||||
* @param s2 Second string to compare.
|
||||
* @return 1 if s1 < s2, 2 if s1 == s2, 3 if s1 > s2, or 0 if not supported by the OS.
|
||||
*/
|
||||
int MacOSStringCompare(const char *s1, const char *s2)
|
||||
{
|
||||
static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
|
||||
if (!supported) return 0;
|
||||
|
||||
CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
|
||||
|
||||
CFStringRef cf1 = CFStringCreateWithCString(kCFAllocatorDefault, s1, kCFStringEncodingUTF8);
|
||||
CFStringRef cf2 = CFStringCreateWithCString(kCFAllocatorDefault, s2, kCFStringEncodingUTF8);
|
||||
|
||||
CFComparisonResult res = CFStringCompareWithOptionsAndLocale(cf1, cf2, CFRangeMake(0, CFStringGetLength(cf1)), flags, _osx_locale);
|
||||
|
||||
CFRelease(cf1);
|
||||
CFRelease(cf2);
|
||||
|
||||
return (int)res + 2;
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ void OSXStringIterator::SetString(const char *s)
|
||||
{
|
||||
const char *string_base = s;
|
||||
|
||||
this->utf16_to_utf8.clear();
|
||||
this->str_info.clear();
|
||||
this->cur_pos = 0;
|
||||
|
||||
/* CoreText operates on UTF-16, thus we have to convert the input string.
|
||||
* To be able to return proper offsets, we have to create a mapping at the same time. */
|
||||
std::vector<UniChar> utf16_str; ///< UTF-16 copy of the string.
|
||||
while (*s != '\0') {
|
||||
size_t idx = s - string_base;
|
||||
|
||||
WChar c = Utf8Consume(&s);
|
||||
if (c < 0x10000) {
|
||||
utf16_str.push_back((UniChar)c);
|
||||
} else {
|
||||
/* Make a surrogate pair. */
|
||||
utf16_str.push_back((UniChar)(0xD800 + ((c - 0x10000) >> 10)));
|
||||
utf16_str.push_back((UniChar)(0xDC00 + ((c - 0x10000) & 0x3FF)));
|
||||
this->utf16_to_utf8.push_back(idx);
|
||||
}
|
||||
this->utf16_to_utf8.push_back(idx);
|
||||
}
|
||||
this->utf16_to_utf8.push_back(s - string_base);
|
||||
|
||||
/* Query CoreText for word and cluster break information. */
|
||||
this->str_info.resize(utf16_to_utf8.size());
|
||||
|
||||
if (utf16_str.size() > 0) {
|
||||
CFStringRef str = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, &utf16_str[0], utf16_str.size(), kCFAllocatorNull);
|
||||
|
||||
/* Get cluster breaks. */
|
||||
for (CFIndex i = 0; i < CFStringGetLength(str); ) {
|
||||
CFRange r = CFStringGetRangeOfComposedCharactersAtIndex(str, i);
|
||||
this->str_info[r.location].char_stop = true;
|
||||
|
||||
i += r.length;
|
||||
}
|
||||
|
||||
/* Get word breaks. */
|
||||
CFStringTokenizerRef tokenizer = CFStringTokenizerCreate(kCFAllocatorDefault, str, CFRangeMake(0, CFStringGetLength(str)), kCFStringTokenizerUnitWordBoundary, _osx_locale);
|
||||
|
||||
CFStringTokenizerTokenType tokenType = kCFStringTokenizerTokenNone;
|
||||
while ((tokenType = CFStringTokenizerAdvanceToNextToken(tokenizer)) != kCFStringTokenizerTokenNone) {
|
||||
/* Skip tokens that are white-space or punctuation tokens. */
|
||||
if ((tokenType & kCFStringTokenizerTokenHasNonLettersMask) != kCFStringTokenizerTokenHasNonLettersMask) {
|
||||
CFRange r = CFStringTokenizerGetCurrentTokenRange(tokenizer);
|
||||
this->str_info[r.location].word_stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(tokenizer);
|
||||
CFRelease(str);
|
||||
}
|
||||
|
||||
/* End-of-string is always a valid stopping point. */
|
||||
this->str_info.back().char_stop = true;
|
||||
this->str_info.back().word_stop = true;
|
||||
}
|
||||
|
||||
/* virtual */ size_t OSXStringIterator::SetCurPosition(size_t pos)
|
||||
{
|
||||
/* Convert incoming position to an UTF-16 string index. */
|
||||
size_t utf16_pos = 0;
|
||||
for (size_t i = 0; i < this->utf16_to_utf8.size(); i++) {
|
||||
if (this->utf16_to_utf8[i] == pos) {
|
||||
utf16_pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sanitize in case we get a position inside a grapheme cluster. */
|
||||
while (utf16_pos > 0 && !this->str_info[utf16_pos].char_stop) utf16_pos--;
|
||||
this->cur_pos = utf16_pos;
|
||||
|
||||
return this->utf16_to_utf8[this->cur_pos];
|
||||
}
|
||||
|
||||
/* virtual */ size_t OSXStringIterator::Next(IterType what)
|
||||
{
|
||||
assert(this->cur_pos <= this->utf16_to_utf8.size());
|
||||
assert(what == StringIterator::ITER_CHARACTER || what == StringIterator::ITER_WORD);
|
||||
|
||||
if (this->cur_pos == this->utf16_to_utf8.size()) return END;
|
||||
|
||||
do {
|
||||
this->cur_pos++;
|
||||
} while (this->cur_pos < this->utf16_to_utf8.size() && (what == ITER_WORD ? !this->str_info[this->cur_pos].word_stop : !this->str_info[this->cur_pos].char_stop));
|
||||
|
||||
return this->cur_pos == this->utf16_to_utf8.size() ? END : this->utf16_to_utf8[this->cur_pos];
|
||||
}
|
||||
|
||||
/* virtual */ size_t OSXStringIterator::Prev(IterType what)
|
||||
{
|
||||
assert(this->cur_pos <= this->utf16_to_utf8.size());
|
||||
assert(what == StringIterator::ITER_CHARACTER || what == StringIterator::ITER_WORD);
|
||||
|
||||
if (this->cur_pos == 0) return END;
|
||||
|
||||
do {
|
||||
this->cur_pos--;
|
||||
} while (this->cur_pos > 0 && (what == ITER_WORD ? !this->str_info[this->cur_pos].word_stop : !this->str_info[this->cur_pos].char_stop));
|
||||
|
||||
return this->utf16_to_utf8[this->cur_pos];
|
||||
}
|
||||
|
||||
/* static */ StringIterator *OSXStringIterator::Create()
|
||||
{
|
||||
if (!MacOSVersionIsAtLeast(10, 5, 0)) return NULL;
|
||||
|
||||
return new OSXStringIterator();
|
||||
}
|
||||
|
||||
#else
|
||||
void MacOSResetScriptCache(FontSize size) {}
|
||||
void MacOSSetCurrentLocaleName(const char *iso_code) {}
|
||||
|
||||
int MacOSStringCompare(const char *s1, const char *s2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* static */ StringIterator *OSXStringIterator::Create()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* static */ ParagraphLayouter *CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) */
|
||||
90
src/os/macosx/string_osx.h
Normal file
90
src/os/macosx/string_osx.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file string_osx.h Functions related to localized text support on OSX. */
|
||||
|
||||
#ifndef STRING_OSX_H
|
||||
#define STRING_OSX_H
|
||||
|
||||
#include "../../gfx_layout.h"
|
||||
#include "../../string_base.h"
|
||||
#include <vector>
|
||||
|
||||
/** String iterator using CoreText as a backend. */
|
||||
class OSXStringIterator : public StringIterator {
|
||||
/** Break info for a character. */
|
||||
struct CharInfo {
|
||||
bool word_stop : 1; ///< Code point is suitable as a word break.
|
||||
bool char_stop : 1; ///< Code point is the start of a grapheme cluster, i.e. a "character".
|
||||
};
|
||||
|
||||
std::vector<CharInfo> str_info; ///< Break information for each code point.
|
||||
std::vector<size_t> utf16_to_utf8; ///< Mapping from UTF-16 code point position to index in the UTF-8 source string.
|
||||
|
||||
size_t cur_pos; ///< Current iteration position.
|
||||
|
||||
public:
|
||||
virtual void SetString(const char *s);
|
||||
virtual size_t SetCurPosition(size_t pos);
|
||||
virtual size_t Next(IterType what);
|
||||
virtual size_t Prev(IterType what);
|
||||
|
||||
static StringIterator *Create();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper class to construct a new #CoreTextParagraphLayout.
|
||||
*/
|
||||
class CoreTextParagraphLayoutFactory {
|
||||
public:
|
||||
/** Helper for GetLayouter, to get the right type. */
|
||||
typedef UniChar CharType;
|
||||
/** Helper for GetLayouter, to get whether the layouter supports RTL. */
|
||||
static const bool SUPPORTS_RTL = true;
|
||||
|
||||
/**
|
||||
* Get the actual ParagraphLayout for the given buffer.
|
||||
* @param buff The begin of the buffer.
|
||||
* @param buff_end The location after the last element in the buffer.
|
||||
* @param fontMapping THe mapping of the fonts.
|
||||
* @return The ParagraphLayout instance.
|
||||
*/
|
||||
static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
|
||||
|
||||
/**
|
||||
* Append a wide character to the internal buffer.
|
||||
* @param buff The buffer to append to.
|
||||
* @param buffer_last The end of the buffer.
|
||||
* @param c The character to add.
|
||||
* @return The number of buffer spaces that were used.
|
||||
*/
|
||||
static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, WChar c)
|
||||
{
|
||||
if (c >= 0x010000U) {
|
||||
/* Character is encoded using surrogates in UTF-16. */
|
||||
if (buff + 1 <= buffer_last) {
|
||||
buff[0] = (CharType)(((c - 0x010000U) >> 10) + 0xD800);
|
||||
buff[1] = (CharType)(((c - 0x010000U) & 0x3FF) + 0xDC00);
|
||||
} else {
|
||||
/* Not enough space in buffer. */
|
||||
*buff = 0;
|
||||
}
|
||||
return 2;
|
||||
} else {
|
||||
*buff = (CharType)(c & 0xFFFF);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void MacOSResetScriptCache(FontSize size);
|
||||
void MacOSSetCurrentLocaleName(const char *iso_code);
|
||||
int MacOSStringCompare(const char *s1, const char *s2);
|
||||
|
||||
#endif /* STRING_OSX_H */
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "../../core/random_func.hpp"
|
||||
#include "../../string_func.h"
|
||||
#include "../../textbuf_gui.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -204,25 +205,22 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
}
|
||||
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
#ifndef __INNOTEK_LIBC__
|
||||
delay(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *FS2OTTD(const char *name) {return name;}
|
||||
const char *OTTD2FS(const char *name) {return name;}
|
||||
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
{
|
||||
// stub only
|
||||
DEBUG(misc, 0, "Failed to open url: %s", url);
|
||||
}
|
||||
|
||||
void SetCurrentThreadName(const char *)
|
||||
{
|
||||
}
|
||||
|
||||
int GetCurrentThreadName(char *str, const char *last) { return 0; }
|
||||
|
||||
void SetSelfAsMainThread() { }
|
||||
|
||||
bool IsMainThread() { return false; }
|
||||
bool IsNonMainThread() { return false; }
|
||||
|
||||
@@ -140,7 +140,7 @@ class CrashLogUnix : public CrashLog {
|
||||
void *signal_instruction_ptr;
|
||||
#endif
|
||||
|
||||
/* virtual */ char *LogOSVersion(char *buffer, const char *last) const
|
||||
char *LogOSVersion(char *buffer, const char *last) const override
|
||||
{
|
||||
struct utsname name;
|
||||
if (uname(&name) < 0) {
|
||||
@@ -160,7 +160,7 @@ class CrashLogUnix : public CrashLog {
|
||||
);
|
||||
}
|
||||
|
||||
/* virtual */ char *LogOSVersionDetail(char *buffer, const char *last) const
|
||||
char *LogOSVersionDetail(char *buffer, const char *last) const override
|
||||
{
|
||||
struct utsname name;
|
||||
if (uname(&name) < 0) return buffer;
|
||||
@@ -177,7 +177,7 @@ class CrashLogUnix : public CrashLog {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* virtual */ char *LogError(char *buffer, const char *last, const char *message) const
|
||||
char *LogError(char *buffer, const char *last, const char *message) const override
|
||||
{
|
||||
buffer += seprintf(buffer, last,
|
||||
"Crash reason:\n"
|
||||
@@ -247,7 +247,7 @@ class CrashLogUnix : public CrashLog {
|
||||
*
|
||||
* Also log GDB information if available
|
||||
*/
|
||||
/* virtual */ char *LogRegisters(char *buffer, const char *last) const
|
||||
char *LogRegisters(char *buffer, const char *last) const
|
||||
{
|
||||
buffer = LogGdbInfo(buffer, last);
|
||||
|
||||
@@ -387,7 +387,7 @@ class CrashLogUnix : public CrashLog {
|
||||
* Note that GCC complains about 'buffer' being clobbered by the longjmp.
|
||||
* This is not an issue as we save/restore it explicitly, so silence the warning.
|
||||
*/
|
||||
/* virtual */ char *LogStacktrace(char *buffer, const char *last) const
|
||||
char *LogStacktrace(char *buffer, const char *last) const override
|
||||
{
|
||||
buffer += seprintf(buffer, last, "Stacktrace:\n");
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "../../debug.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../fios.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
@@ -43,39 +44,24 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __MORPHOS__
|
||||
#include <exec/types.h>
|
||||
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
|
||||
|
||||
/* The system supplied definition of SIG_IGN does not match */
|
||||
#undef SIG_IGN
|
||||
#define SIG_IGN (void (*)(int))1
|
||||
#endif /* __MORPHOS__ */
|
||||
|
||||
#ifdef __AMIGA__
|
||||
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
|
||||
// ULONG __stack =
|
||||
#ifndef NO_THREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(WITH_SDL)
|
||||
# if defined(WITH_SDL)
|
||||
/* the mac implementation needs this file included in the same file as main() */
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
# include <SDL.h>
|
||||
# endif
|
||||
|
||||
# include "../macosx/macos.h"
|
||||
#endif
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool FiosIsRoot(const char *path)
|
||||
{
|
||||
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
|
||||
return path[1] == '\0';
|
||||
#else
|
||||
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
||||
const char *s = strchr(path, ':');
|
||||
return s != NULL && s[1] == '\0';
|
||||
#endif
|
||||
}
|
||||
|
||||
void FiosGetDrives(FileList &file_list)
|
||||
@@ -106,15 +92,8 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
int res;
|
||||
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
||||
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
||||
if (FiosIsRoot(path)) {
|
||||
res = seprintf(filename, lastof(filename), "%s:%s", path, ent->d_name);
|
||||
} else // XXX - only next line!
|
||||
#else
|
||||
assert(path[strlen(path) - 1] == PATHSEPCHAR);
|
||||
if (strlen(path) > 2) assert(path[strlen(path) - 2] != PATHSEPCHAR);
|
||||
#endif
|
||||
res = seprintf(filename, lastof(filename), "%s%s", path, ent->d_name);
|
||||
|
||||
/* Could we fully concatenate the path and filename? */
|
||||
@@ -294,74 +273,7 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
#endif
|
||||
|
||||
|
||||
/* multi os compatible sleep function */
|
||||
|
||||
#ifdef __AMIGA__
|
||||
/* usleep() implementation */
|
||||
# include <devices/timer.h>
|
||||
# include <dos/dos.h>
|
||||
|
||||
extern struct Device *TimerBase = NULL;
|
||||
extern struct MsgPort *TimerPort = NULL;
|
||||
extern struct timerequest *TimerRequest = NULL;
|
||||
#endif /* __AMIGA__ */
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
#if defined(__BEOS__)
|
||||
snooze(milliseconds * 1000);
|
||||
#elif defined(__AMIGA__)
|
||||
{
|
||||
ULONG signals;
|
||||
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
|
||||
|
||||
/* send IORequest */
|
||||
TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
|
||||
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000;
|
||||
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000;
|
||||
SendIO((struct IORequest *)TimerRequest);
|
||||
|
||||
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
|
||||
AbortIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
WaitIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
#else
|
||||
usleep(milliseconds * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef __APPLE__
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
uint count = 1;
|
||||
#ifdef HAS_SYSCTL
|
||||
int ncpu = 0;
|
||||
size_t len = sizeof(ncpu);
|
||||
|
||||
#ifdef OPENBSD
|
||||
int name[2];
|
||||
name[0] = CTL_HW;
|
||||
name[1] = HW_NCPU;
|
||||
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
|
||||
ncpu = 0;
|
||||
}
|
||||
#else
|
||||
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
||||
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
||||
}
|
||||
#endif /* #ifdef OPENBSD */
|
||||
|
||||
if (ncpu > 0) count = ncpu;
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
long res = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (res > 0) count = res;
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
{
|
||||
pid_t child_pid = fork();
|
||||
@@ -375,4 +287,56 @@ void OSOpenBrowser(const char *url)
|
||||
DEBUG(misc, 0, "Failed to open url: %s", url);
|
||||
exit(0);
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
void SetCurrentThreadName(const char *threadName) {
|
||||
#if !defined(NO_THREADS) && defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
if (threadName) pthread_setname_np(pthread_self(), threadName);
|
||||
#endif /* __GLIBC_PREREQ(2, 12) */
|
||||
#endif /* !defined(NO_THREADS) && defined(__GLIBC__) */
|
||||
#if defined(__APPLE__)
|
||||
MacOSSetThreadName(threadName);
|
||||
#endif /* defined(__APPLE__) */
|
||||
}
|
||||
|
||||
int GetCurrentThreadName(char *str, const char *last)
|
||||
{
|
||||
#if !defined(NO_THREADS) && defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
char buffer[16];
|
||||
int result = pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
|
||||
if (result == 0) {
|
||||
return seprintf(str, last, "%s", buffer);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static pthread_t main_thread;
|
||||
|
||||
void SetSelfAsMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
main_thread = pthread_self();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
return main_thread == pthread_self();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsNonMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
return main_thread != pthread_self();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
/* printf format specification for 32/64-bit addresses. */
|
||||
#ifdef _M_AMD64
|
||||
#define PRINTF_PTR "0x%016IX"
|
||||
@@ -48,14 +45,14 @@ class CrashLogWindows : public CrashLog {
|
||||
/** Information about the encountered exception */
|
||||
EXCEPTION_POINTERS *ep;
|
||||
|
||||
/* virtual */ char *LogOSVersion(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogError(char *buffer, const char *last, const char *message) const;
|
||||
/* virtual */ char *LogStacktrace(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogRegisters(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogModules(char *buffer, const char *last) const;
|
||||
char *LogOSVersion(char *buffer, const char *last) const override;
|
||||
char *LogError(char *buffer, const char *last, const char *message) const override;
|
||||
char *LogStacktrace(char *buffer, const char *last) const override;
|
||||
char *LogRegisters(char *buffer, const char *last) const override;
|
||||
char *LogModules(char *buffer, const char *last) const override;
|
||||
public:
|
||||
#if defined(_MSC_VER) || defined(WITH_DBGHELP)
|
||||
/* virtual */ int WriteCrashDump(char *filename, const char *filename_last) const;
|
||||
int WriteCrashDump(char *filename, const char *filename_last) const override;
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const;
|
||||
#else
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const { return buffer; }
|
||||
@@ -329,6 +326,9 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
|
||||
|
||||
#if defined(_MSC_VER) || defined(WITH_DBGHELP)
|
||||
#if defined(_MSC_VER)
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
#pragma warning(disable:4091)
|
||||
#endif
|
||||
#include <dbghelp.h>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define APSTUDIO_HIDDEN_SYMBOLS
|
||||
#include "windows.h"
|
||||
#undef APSTUDIO_HIDDEN_SYMBOLS
|
||||
#ifdef MSVC
|
||||
#ifndef __MINGW32__
|
||||
#include "winres.h"
|
||||
#else
|
||||
#define IDC_STATIC (-1) // all static controls
|
||||
@@ -79,8 +79,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,9,0,!!ISODATE!!
|
||||
PRODUCTVERSION 1,9,0,!!ISODATE!!
|
||||
FILEVERSION 1,10,0,!!ISODATE!!
|
||||
PRODUCTVERSION 1,10,0,!!ISODATE!!
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -100,7 +100,7 @@ BEGIN
|
||||
VALUE "FileDescription", "OpenTTD\0"
|
||||
VALUE "FileVersion", "!!VERSION!!\0"
|
||||
VALUE "InternalName", "openttd\0"
|
||||
VALUE "LegalCopyright", "Copyright \xA9 OpenTTD Developers 2002-2018. All Rights Reserved.\0"
|
||||
VALUE "LegalCopyright", "Copyright \xA9 OpenTTD Developers 2002-2019. All Rights Reserved.\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "openttd.exe\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
@@ -117,5 +117,9 @@ END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#ifdef __MINGW32__
|
||||
1 24 "..\\..\\..\\projects\\dpi_aware.manifest"
|
||||
#endif
|
||||
|
||||
#endif // Neutral (Default) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -106,12 +106,12 @@ public:
|
||||
};
|
||||
|
||||
/** A single line worth of VisualRuns. */
|
||||
class UniscribeLine : public AutoDeleteSmallVector<UniscribeVisualRun *, 4>, public ParagraphLayouter::Line {
|
||||
class UniscribeLine : public AutoDeleteSmallVector<UniscribeVisualRun *>, public ParagraphLayouter::Line {
|
||||
public:
|
||||
virtual int GetLeading() const;
|
||||
virtual int GetWidth() const;
|
||||
virtual int CountRuns() const { return this->Length(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return *this->Get(run); }
|
||||
virtual int CountRuns() const { return (uint)this->size(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(WChar c) const
|
||||
{
|
||||
@@ -195,6 +195,7 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
for (int i = 0; i < range.len; i++) {
|
||||
if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) {
|
||||
range.ft_glyphs[range.char_to_glyph[i]] = range.font->fc->MapCharToGlyph(buff[range.pos + i]);
|
||||
range.offsets[range.char_to_glyph[i]].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[range.char_to_glyph[i]])->height - 1; // Align sprite glyphs to font baseline.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,8 +282,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
if (length == 0) return NULL;
|
||||
|
||||
/* Can't layout our in-built sprite fonts. */
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
if (i->second->fc->IsBuiltInFont()) return NULL;
|
||||
for (auto const &pair : fontMapping) {
|
||||
if (pair.second->fc->IsBuiltInFont()) return NULL;
|
||||
}
|
||||
|
||||
/* Itemize text. */
|
||||
@@ -295,12 +296,12 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
|
||||
int cur_pos = 0;
|
||||
std::vector<SCRIPT_ITEM>::iterator cur_item = items.begin();
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
while (cur_pos < i->first && cur_item != items.end() - 1) {
|
||||
for (auto const &i : fontMapping) {
|
||||
while (cur_pos < i.first && cur_item != items.end() - 1) {
|
||||
/* Add a range that spans the intersection of the remaining item and font run. */
|
||||
int stop_pos = min(i->first, (cur_item + 1)->iCharPos);
|
||||
int stop_pos = min(i.first, (cur_item + 1)->iCharPos);
|
||||
assert(stop_pos - cur_pos > 0);
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i->second, cur_item->a));
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i.second, cur_item->a));
|
||||
|
||||
/* Shape the range. */
|
||||
if (!UniscribeShapeRun(buff, ranges.back())) {
|
||||
@@ -423,7 +424,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return NULL;
|
||||
}
|
||||
|
||||
*line->Append() = new UniscribeVisualRun(run, cur_pos);
|
||||
line->push_back(new UniscribeVisualRun(run, cur_pos));
|
||||
cur_pos += run.total_advance;
|
||||
}
|
||||
|
||||
@@ -447,8 +448,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
{
|
||||
int leading = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
leading = max(leading, (*run)->GetLeading());
|
||||
for (const UniscribeVisualRun *run : *this) {
|
||||
leading = max(leading, run->GetLeading());
|
||||
}
|
||||
|
||||
return leading;
|
||||
@@ -461,8 +462,8 @@ int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetWidth() const
|
||||
{
|
||||
int length = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
length += (*run)->GetAdvance();
|
||||
for (const UniscribeVisualRun *run : *this) {
|
||||
length += run->GetAdvance();
|
||||
}
|
||||
|
||||
return length;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <regstr.h>
|
||||
#define NO_SHOBJIDL_SORTDIRECTION // Avoid multiple definition of SORT_ASCENDING
|
||||
#include <shlobj.h> /* SHGetFolderPath */
|
||||
#include <shellapi.h>
|
||||
#include "win32.h"
|
||||
@@ -29,11 +30,9 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../../language.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
/* Due to TCHAR, strncat and strncpy have to remain (for a while). */
|
||||
#include "../../safeguards.h"
|
||||
#undef strncat
|
||||
#undef strncpy
|
||||
|
||||
bool _in_event_loop_post_crash;
|
||||
|
||||
@@ -83,7 +82,7 @@ void ShowOSErrorBox(const char *buf, bool system)
|
||||
{
|
||||
_in_event_loop_post_crash = true;
|
||||
MyShowCursor(true);
|
||||
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP);
|
||||
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP | MB_TASKMODAL);
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
@@ -303,7 +302,7 @@ void CreateConsole()
|
||||
if (_has_console) return;
|
||||
_has_console = true;
|
||||
|
||||
AllocConsole();
|
||||
if (!AllocConsole()) return;
|
||||
|
||||
hand = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
GetConsoleScreenBufferInfo(hand, &coninfo);
|
||||
@@ -548,12 +547,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
}
|
||||
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
Sleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to OpenTTD's encoding from that of the local environment.
|
||||
* When the project is built in UNICODE, the system codepage is irrelevant and
|
||||
@@ -628,11 +621,11 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||
* Convert from OpenTTD's encoding to that of the environment in
|
||||
* UNICODE. OpenTTD encoding is UTF8, local is wide
|
||||
* @param name pointer to a valid string that will be converted
|
||||
* @param utf16_buf pointer to a valid wide-char buffer that will receive the
|
||||
* @param system_buf pointer to a valid wide-char buffer that will receive the
|
||||
* converted string
|
||||
* @param buflen length in wide characters of the receiving buffer
|
||||
* @param console_cp convert to the console encoding instead of the normal system encoding.
|
||||
* @return pointer to utf16_buf. If conversion fails the string is of zero-length
|
||||
* @return pointer to system_buf. If conversion fails the string is of zero-length
|
||||
*/
|
||||
TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
|
||||
{
|
||||
@@ -735,14 +728,6 @@ const char *GetCurrentLocale(const char *)
|
||||
return retbuf;
|
||||
}
|
||||
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
static WCHAR _cur_iso_locale[16] = L"";
|
||||
|
||||
@@ -807,6 +792,42 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
||||
return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, s1_buf, -1, s2_buf, -1);
|
||||
}
|
||||
|
||||
static DWORD main_thread_id;
|
||||
|
||||
void SetSelfAsMainThread()
|
||||
{
|
||||
main_thread_id = GetCurrentThreadId();
|
||||
}
|
||||
|
||||
bool IsMainThread()
|
||||
{
|
||||
return main_thread_id == GetCurrentThreadId();
|
||||
}
|
||||
|
||||
bool IsNonMainThread()
|
||||
{
|
||||
return main_thread_id != GetCurrentThreadId();
|
||||
}
|
||||
|
||||
static std::map<DWORD, std::string> _thread_name_map;
|
||||
static std::mutex _thread_name_map_mutex;
|
||||
|
||||
static void Win32SetThreadName(uint id, const char *name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
|
||||
_thread_name_map[id] = name;
|
||||
}
|
||||
|
||||
int GetCurrentThreadName(char *str, const char *last)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
|
||||
auto iter = _thread_name_map.find(GetCurrentThreadId());
|
||||
if (iter != _thread_name_map.end()) {
|
||||
return seprintf(str, last, "%s", iter->second.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* Based on code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
|
||||
const DWORD MS_VC_EXCEPTION = 0x406D1388;
|
||||
@@ -821,12 +842,14 @@ PACK_N(struct THREADNAME_INFO {
|
||||
/**
|
||||
* Signal thread name to any attached debuggers.
|
||||
*/
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
void SetCurrentThreadName(const char *threadName)
|
||||
{
|
||||
Win32SetThreadName(GetCurrentThreadId(), threadName);
|
||||
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = threadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwThreadID = -1;
|
||||
info.dwFlags = 0;
|
||||
|
||||
#pragma warning(push)
|
||||
@@ -837,4 +860,9 @@ void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
}
|
||||
#pragma warning(pop)
|
||||
}
|
||||
#else
|
||||
void SetCurrentThreadName(const char *)
|
||||
{
|
||||
Win32SetThreadName(GetCurrentThreadId(), threadName);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,12 +39,6 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
|
||||
#define SHGFP_TYPE_CURRENT 0
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
|
||||
#else
|
||||
static inline void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
|
||||
#endif
|
||||
|
||||
void Win32SetCurrentLocaleName(const char *iso_code);
|
||||
int OTTDStringCompare(const char *s1, const char *s2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user