Browse Source

crop support and confirmed y0max != maxy0 aren't the same

Odilitime 5 years ago
parent
commit
360d09cb46
  1. 17
      src/graphics/text/TextRasterizer.cpp
  2. 3
      src/graphics/text/TextRasterizer.h

17
src/graphics/text/TextRasterizer.cpp

@ -60,7 +60,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r @@ -60,7 +60,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r
return nullptr;
}
if (!buffer) {
std::cout << "TextRasterizer::rasterize - no font loaded" << std::endl;
std::cout << "TextRasterizer::size - no font loaded" << std::endl;
return nullptr;
}
@ -133,7 +133,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r @@ -133,7 +133,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r
if (request.noWrap) {
glyphCount = i;
// we're done
std::cout << "TextRasterizer::rasterize - newline found no wrap is on" << std::endl;
std::cout << "TextRasterizer::size - newline found no wrap is on" << std::endl;
break;
} else {
xmax=std::max(xmax, cx);
@ -167,6 +167,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r @@ -167,6 +167,7 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r
// update glyph space allocation
cx += xa;
// note all over cy is in -
cy += ya; // is normal for y0 at bottom
// update glyph maxes
@ -180,6 +181,10 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r @@ -180,6 +181,10 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r
// track new max width
xmax=std::max(xmax, cx);
// crop overflow
if (request.cropHeight && cy > request.cropHeight) {
break; // stop adding characters
}
}
if (response->leftPadding) {
xmax += response->leftPadding; // increase width;
@ -189,9 +194,12 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r @@ -189,9 +194,12 @@ std::unique_ptr<sizeResponse> TextRasterizer::size(const rasterizationRequest &r
response->height = -cy;
response->width = xmax;
//std::cout << "lines: " << lines << " wrapToX: " << wrapToX << " startX: " << x << " xmax: " << xmax << std::endl;
// confirmed we aren't the same
/*
if (response->y0max != maxy0) {
std::cout << "TextRasterizer::size - resp.y0max: " << response->y0max << " maxy0: " << maxy0 << std::endl;
}
*/
//std::cout << "y1max: " << y1max << " lines: " << response->lines << std::endl;
int textureHeight = (y1max - response->y0max) * static_cast<int>(response->lines);
//int textureHeight = y1max * response->lines;
@ -346,6 +354,11 @@ std::unique_ptr<rasterizationResponse> TextRasterizer::rasterize(const rasteriza @@ -346,6 +354,11 @@ std::unique_ptr<rasterizationResponse> TextRasterizer::rasterize(const rasteriza
//std::cout << "textWrap - cx reset to: " << cx << " cy is now: " << cy << std::endl;
}
//std::cout << "placing glyph[" << text[i] << "] at " << cx << " cy is now: " << cy << std::endl;
// crop overflow
if (request.cropHeight && cy > request.cropHeight) {
break; // stop adding characters
}
if (cx < request.sourceStartX) {
// skip ahead

3
src/graphics/text/TextRasterizer.h

@ -40,6 +40,9 @@ struct rasterizationRequest { @@ -40,6 +40,9 @@ struct rasterizationRequest {
// scrolling basically:
int sourceStartX = 0; // start reading text source at and place at destination 0
int sourceStartY = 0;
// overflow (0 means no limit)
int cropWidth = 0;
int cropHeight = 0;
bool noWrap = false; // different than overflow but related
unsigned int maxTextureSize = 0;
};

Loading…
Cancel
Save