diff options
Diffstat (limited to 'cocoa/PlatCocoa.mm')
-rw-r--r-- | cocoa/PlatCocoa.mm | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index c3a5e1d48..239884341 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -357,8 +357,6 @@ const Supports SupportsCocoa[] = { SurfaceImpl::SurfaceImpl() { gc = NULL; - textLayout.reset(new QuartzTextLayout()); - bitmapData.reset(); // Release will try and delete bitmapData if != nullptr bitmapWidth = 0; bitmapHeight = 0; @@ -368,8 +366,6 @@ SurfaceImpl::SurfaceImpl() { SurfaceImpl::SurfaceImpl(const SurfaceImpl *surface, int width, int height) { - textLayout.reset(new QuartzTextLayout()); - // Create a new bitmap context, along with the RAM for the bitmap itself bitmapWidth = width; bitmapHeight = height; @@ -1269,8 +1265,8 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, const Font *font_, XYPOSITI CGColorRelease(color); - textLayout->setText(text, encoding, style); - textLayout->draw(gc, rc.left, ybase); + QuartzTextLayout layoutDraw(text, encoding, style); + layoutDraw.draw(gc, rc.left, ybase); } //-------------------------------------------------------------------------------------------------- @@ -1281,10 +1277,10 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI return; } CFStringEncoding encoding = EncodingFromCharacterSet(UnicodeMode(), style->getCharacterSet()); - const CFStringEncoding encodingUsed = - textLayout->setText(text, encoding, style); + QuartzTextLayout layoutMeasure(text, encoding, style); + const CFStringEncoding encodingUsed = layoutMeasure.getEncoding(); - CTLineRef mLine = textLayout->getCTLine(); + CTLineRef mLine = layoutMeasure.getCTLine(); assert(mLine); if (encodingUsed != encoding) { @@ -1298,7 +1294,7 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI if (UnicodeMode()) { // Map the widths given for UTF-16 characters back onto the UTF-8 input string - CFIndex fit = textLayout->getStringLength(); + CFIndex fit = layoutMeasure.getStringLength(); int ui=0; int i=0; std::vector<CGFloat> linePositions(fit); @@ -1344,9 +1340,9 @@ XYPOSITION SurfaceImpl::WidthText(const Font *font_, std::string_view text) { return 1; } CFStringEncoding encoding = EncodingFromCharacterSet(UnicodeMode(), style->getCharacterSet()); - textLayout->setText(text, encoding, style); + QuartzTextLayout layoutMeasure(text, encoding, style); - return static_cast<XYPOSITION>(textLayout->MeasureStringWidth()); + return static_cast<XYPOSITION>(layoutMeasure.MeasureStringWidth()); } //-------------------------------------------------------------------------------------------------- @@ -1386,8 +1382,8 @@ void SurfaceImpl::DrawTextTransparentUTF8(PRectangle rc, const Font *font_, XYPO CGColorRelease(color); - textLayout->setText(text, encoding, style); - textLayout->draw(gc, rc.left, ybase); + QuartzTextLayout layoutDraw(text, encoding, style); + layoutDraw.draw(gc, rc.left, ybase); } //-------------------------------------------------------------------------------------------------- @@ -1397,11 +1393,11 @@ void SurfaceImpl::MeasureWidthsUTF8(const Font *font_, std::string_view text, XY if (!style) { return; } - const CFStringEncoding encoding = kCFStringEncodingUTF8; - const CFStringEncoding encodingUsed = - textLayout->setText(text, encoding, style); + constexpr CFStringEncoding encoding = kCFStringEncodingUTF8; + QuartzTextLayout layoutMeasure(text, encoding, style); + const CFStringEncoding encodingUsed = layoutMeasure.getEncoding(); - CTLineRef mLine = textLayout->getCTLine(); + CTLineRef mLine = layoutMeasure.getCTLine(); assert(mLine); if (encodingUsed != encoding) { @@ -1414,7 +1410,7 @@ void SurfaceImpl::MeasureWidthsUTF8(const Font *font_, std::string_view text, XY } // Map the widths given for UTF-16 characters back onto the UTF-8 input string - CFIndex fit = textLayout->getStringLength(); + CFIndex fit = layoutMeasure.getStringLength(); int ui=0; int i=0; std::vector<CGFloat> linePositions(fit); @@ -1442,9 +1438,8 @@ XYPOSITION SurfaceImpl::WidthTextUTF8(const Font *font_, std::string_view text) if (!style) { return 1; } - textLayout->setText(text, kCFStringEncodingUTF8, style); - - return static_cast<XYPOSITION>(textLayout->MeasureStringWidth()); + QuartzTextLayout layoutMeasure(text, kCFStringEncodingUTF8, style); + return static_cast<XYPOSITION>(layoutMeasure.MeasureStringWidth()); } //-------------------------------------------------------------------------------------------------- |