Image owns its alt text.
This commit is contained in:
20
dw/image.cc
20
dw/image.cc
@ -131,11 +131,11 @@ int ImageMapsList::link (object::Object *key, int x, int y)
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Image::Image(const char *altText)
|
||||
Image::Image(const std::optional< std::string_view > altText)
|
||||
{
|
||||
DBG_OBJ_CREATE ("dw::Image");
|
||||
registerName ("dw::Image", typeid(*this));
|
||||
this->altText = altText ? dStrdup (altText) : NULL;
|
||||
this->altText = altText;
|
||||
altTextWidth = -1; // not yet calculated
|
||||
buffer = NULL;
|
||||
bufWidth = bufHeight = -1;
|
||||
@ -151,8 +151,6 @@ Image::Image(const char *altText)
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if (altText)
|
||||
free(altText);
|
||||
if (buffer)
|
||||
buffer->unref ();
|
||||
if (mapKey)
|
||||
@ -177,10 +175,10 @@ void Image::sizeRequestSimpl (core::Requisition *requisition)
|
||||
requisition->ascent = buffer->getRootHeight ();
|
||||
requisition->descent = 0;
|
||||
} else {
|
||||
if (altText && altText[0]) {
|
||||
if (altText && altText.value()[0]) {
|
||||
if (altTextWidth == -1)
|
||||
altTextWidth =
|
||||
layout->textWidth (getStyle()->font, altText, strlen (altText));
|
||||
layout->textWidth (getStyle()->font, altText.value().c_str(), altText.value().size());
|
||||
|
||||
requisition->width = altTextWidth;
|
||||
requisition->ascent = getStyle()->font->ascent;
|
||||
@ -220,10 +218,10 @@ void Image::getExtremesSimpl (core::Extremes *extremes)
|
||||
if (buffer)
|
||||
contentWidth = buffer->getRootWidth ();
|
||||
else {
|
||||
if (altText && altText[0]) {
|
||||
if (altText && altText.value()[0]) {
|
||||
if (altTextWidth == -1)
|
||||
altTextWidth =
|
||||
layout->textWidth (getStyle()->font, altText, strlen (altText));
|
||||
layout->textWidth (getStyle()->font, altText.value().c_str(), altText.value().size());
|
||||
contentWidth = altTextWidth;
|
||||
} else
|
||||
contentWidth = 0;
|
||||
@ -422,14 +420,14 @@ void Image::draw (core::View *view, core::Rectangle *area,
|
||||
} else {
|
||||
core::View *clippingView;
|
||||
|
||||
if (altText && altText[0]) {
|
||||
if (altText && altText.value()[0]) {
|
||||
core::View *usedView = view;
|
||||
|
||||
clippingView = NULL;
|
||||
|
||||
if (altTextWidth == -1)
|
||||
altTextWidth =
|
||||
layout->textWidth (getStyle()->font, altText, strlen (altText));
|
||||
layout->textWidth (getStyle()->font, altText.value().c_str(), altText.value().size());
|
||||
|
||||
if ((getContentWidth() < altTextWidth) ||
|
||||
(getContentHeight() <
|
||||
@ -445,7 +443,7 @@ void Image::draw (core::View *view, core::Rectangle *area,
|
||||
core::style::Color::SHADING_NORMAL,
|
||||
allocation.x + boxOffsetX (),
|
||||
allocation.y + boxOffsetY (),
|
||||
getContentWidth(), getContentHeight(), altText);
|
||||
getContentWidth(), getContentHeight(), altText.value().c_str());
|
||||
|
||||
if (clippingView)
|
||||
view->mergeClippingView (clippingView);
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include "core.hh"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace dw {
|
||||
|
||||
/**
|
||||
@ -115,7 +118,7 @@ public:
|
||||
class Image: public core::Widget, public core::ImgRenderer
|
||||
{
|
||||
private:
|
||||
char *altText;
|
||||
std::optional< std::string > altText;
|
||||
core::Imgbuf *buffer;
|
||||
int bufWidth, bufHeight;
|
||||
int altTextWidth;
|
||||
@ -145,7 +148,7 @@ protected:
|
||||
//core::Iterator *iterator (Content::Type mask, bool atEnd);
|
||||
|
||||
public:
|
||||
Image(const char *altText);
|
||||
Image(std::optional< std::string_view > altText);
|
||||
~Image();
|
||||
|
||||
// For images, the minimal width is not well defined, and
|
||||
|
Reference in New Issue
Block a user