aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2018-04-22 08:22:53 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2018-04-22 08:22:53 +1000
commitde2433ffb9b9c98060a607427bd04b4c9e1d9c76 (patch)
tree5b18b0ec8fa10c6eddaa0131c57e5043da4fd966
parent501d1f9ab73f49c835aa4e2028eb33e9a83b065b (diff)
downloadscintilla-mirror-de2433ffb9b9c98060a607427bd04b4c9e1d9c76.tar.gz
Backport: Reduce casts by moving casting from char* to UInt8* into QuartzTextLayout::SetText
and adding helper TextStyleFromFont to cast from Font to QuartzTextStyle. Backport of changeset 6729:2d72313a7d6d.
-rw-r--r--cocoa/PlatCocoa.mm26
-rw-r--r--cocoa/QuartzTextLayout.h6
2 files changed, 20 insertions, 12 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 97fee88d7..ac147b6b5 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -103,10 +103,18 @@ Font::~Font()
//--------------------------------------------------------------------------------------------------
+static QuartzTextStyle *TextStyleFromFont(Font &f) {
+ return static_cast<QuartzTextStyle *>(f.GetID());
+}
+
+//--------------------------------------------------------------------------------------------------
+
static int FontCharacterSet(Font &f) {
- return static_cast<QuartzTextStyle *>(f.GetID())->getCharacterSet();
+ return TextStyleFromFont(f)->getCharacterSet();
}
+//--------------------------------------------------------------------------------------------------
+
/**
* Creates a CTFontRef with the given properties.
*/
@@ -921,12 +929,12 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION yba
ColourDesired colour(fore.AsLong());
CGColorRef color = CGColorCreateGenericRGB(colour.GetRed()/255.0,colour.GetGreen()/255.0,colour.GetBlue()/255.0,1.0);
- QuartzTextStyle* style = static_cast<QuartzTextStyle*>(font_.GetID());
+ QuartzTextStyle *style = TextStyleFromFont(font_);
style->setCTStyleColor(color);
CGColorRelease(color);
- textLayout->setText (reinterpret_cast<const UInt8*>(s), len, encoding, *static_cast<QuartzTextStyle*>(font_.GetID()));
+ textLayout->setText(s, len, encoding, *style);
textLayout->draw(rc.left, ybase);
}
@@ -935,7 +943,7 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION yba
void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions)
{
CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_));
- textLayout->setText (reinterpret_cast<const UInt8*>(s), len, encoding, *static_cast<QuartzTextStyle*>(font_.GetID()));
+ textLayout->setText(s, len, encoding, *TextStyleFromFont(font_));
CTLineRef mLine = textLayout->getCTLine();
assert(mLine != NULL);
@@ -984,7 +992,7 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
if (font_.GetID())
{
CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_));
- textLayout->setText (reinterpret_cast<const UInt8*>(s), len, encoding, *static_cast<QuartzTextStyle*>(font_.GetID()));
+ textLayout->setText(s, len, encoding, *TextStyleFromFont(font_));
return static_cast<XYPOSITION>(textLayout->MeasureStringWidth());
}
@@ -996,7 +1004,7 @@ XYPOSITION SurfaceImpl::WidthChar(Font &font_, char ch) {
if (font_.GetID())
{
CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_));
- textLayout->setText (reinterpret_cast<const UInt8*>(str), 1, encoding, *static_cast<QuartzTextStyle*>(font_.GetID()));
+ textLayout->setText(str, 1, encoding, *TextStyleFromFont(font_));
return textLayout->MeasureStringWidth();
}
@@ -1012,7 +1020,7 @@ XYPOSITION SurfaceImpl::Ascent(Font &font_) {
if (!font_.GetID())
return 1;
- float ascent = static_cast<QuartzTextStyle*>( font_.GetID() )->getAscent();
+ float ascent = TextStyleFromFont(font_)->getAscent();
return ascent + 0.5f;
}
@@ -1021,7 +1029,7 @@ XYPOSITION SurfaceImpl::Descent(Font &font_) {
if (!font_.GetID())
return 1;
- float descent = static_cast<QuartzTextStyle*>( font_.GetID() )->getDescent();
+ float descent = TextStyleFromFont(font_)->getDescent();
return descent + 0.5f;
}
@@ -1625,7 +1633,7 @@ void ListBoxImpl::SetFont(Font& font_)
{
// NSCell setFont takes an NSFont* rather than a CTFontRef but they
// are the same thing toll-free bridged.
- QuartzTextStyle* style = static_cast<QuartzTextStyle*>(font_.GetID());
+ QuartzTextStyle *style = TextStyleFromFont(font_);
font.Release();
font.SetID(new QuartzTextStyle(*style));
NSFont *pfont = (NSFont *)style->getFontRef();
diff --git a/cocoa/QuartzTextLayout.h b/cocoa/QuartzTextLayout.h
index 33869ae6e..0f813f301 100644
--- a/cocoa/QuartzTextLayout.h
+++ b/cocoa/QuartzTextLayout.h
@@ -42,9 +42,9 @@ public:
}
}
- inline void setText( const UInt8* buffer, size_t byteLength, CFStringEncoding encoding, const QuartzTextStyle& r )
- {
- CFStringRef str = CFStringCreateWithBytes( NULL, buffer, byteLength, encoding, false );
+ void setText(const char *buffer, size_t byteLength, CFStringEncoding encoding, const QuartzTextStyle &r) {
+ const UInt8 *puiBuffer = reinterpret_cast<const UInt8 *>(buffer);
+ CFStringRef str = CFStringCreateWithBytes(NULL, puiBuffer, byteLength, encoding, false);
if (!str)
return;