Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/irrlicht/include/GlyphLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ inline void eraseTopLargerThan(std::vector<GlyphLayout>& gls,
}

inline core::dimension2d<u32> getGlyphLayoutsDimension(
const std::vector<GlyphLayout>& gls, s32 height_per_line, f32 inverse_shaping,
f32 scale, s32 cluster = -1)
const std::vector<GlyphLayout>& gls, s32 height_per_line, s32 height_per_glyph,
f32 inverse_shaping, f32 scale, s32 cluster = -1)
{
core::dimension2d<f32> dim(0.0f, 0.0f);
core::dimension2d<f32> this_line(0.0f, (f32)height_per_line);
Expand Down Expand Up @@ -148,7 +148,7 @@ inline core::dimension2d<u32> getGlyphLayoutsDimension(
break;
}

dim.Height += this_line.Height;
dim.Height += height_per_glyph;
if (dim.Width < this_line.Width)
dim.Width = this_line.Width;

Expand Down Expand Up @@ -328,7 +328,7 @@ inline bool getDrawOffset(const core::rect<s32>& position, bool hcenter,
if (hcenter || vcenter || clip)
{
text_dimension = gui::getGlyphLayoutsDimension(
gls, next_line_height, inverse_shaping, scale);
gls, next_line_height, next_line_height, inverse_shaping, scale, -1);

if (hcenter)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/irrlicht/include/IGUIFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class IGUIFont : public virtual IReferenceCounted

//! Returns the height per line (including padding between 2 lines)
virtual s32 getHeightPerLine() const = 0;
virtual s32 getHeightPerGlyph() const = 0;


//! Define which characters should not be drawn by the font.
/** For example " " would not draw any space which is usually blank in
Expand Down
10 changes: 8 additions & 2 deletions lib/irrlicht/source/Irrlicht/CGUIButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,15 @@ void CGUIButton::draw()
}

if (font)
font->draw(Text.c_str(), rect,
{
const core::dimension2d<u32> dim = font->getDimension(Text.c_str());
core::rect<s32> text_rect = rect;
text_rect.UpperLeftCorner.Y += (rect.getHeight() - (s32)dim.Height) / 2;
text_rect.LowerRightCorner.Y = text_rect.UpperLeftCorner.Y + (s32)dim.Height;
font->draw(Text.c_str(), text_rect,
skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
true, true, &AbsoluteClippingRect);
true, false, &AbsoluteClippingRect);
}
}

IGUIElement::draw();
Expand Down
2 changes: 2 additions & 0 deletions lib/irrlicht/source/Irrlicht/CGUIFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class CGUIFont : public IGUIFontBitmap
virtual void setKerningHeight (s32 kerning);

virtual s32 getHeightPerLine() const { return (s32)getDimension(L"A").Height + getKerningHeight(); }
virtual s32 getHeightPerGlyph() const { return (s32)getDimension(L"A").Height; }


//! set an Pixel Offset on Drawing ( scale position on width )
virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const;
Expand Down
8 changes: 4 additions & 4 deletions lib/irrlicht/source/Irrlicht/CGUIStaticText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ s32 CGUIStaticText::getTextHeight() const
return 0;

auto dim = getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(), font->getScale());
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(), font->getScale());

return dim.Height;
return dim.Height + 2 * (font->getHeightPerLine() - font->getHeightPerGlyph());
}


Expand All @@ -311,7 +311,7 @@ s32 CGUIStaticText::getTextWidth() const
return 0;

auto dim = getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(), font->getScale());
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(), font->getScale());

return dim.Width;
}
Expand Down Expand Up @@ -486,7 +486,7 @@ void CGUIStaticText::getDrawPosition(core::rect<s32>* draw_pos, bool* hcenter, c
core::rect<s32> r = *draw_pos;
IGUIFont* font = getActiveFont();
auto dim = getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(), font->getScale());
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(), font->getScale());

s32 totalHeight = dim.Height;
if (VAlign == EGUIA_CENTER)
Expand Down
41 changes: 34 additions & 7 deletions src/font/font_with_face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ FontWithFace::FontWithFace(const std::string& name)
m_fallback_font = NULL;
m_fallback_font_scale = 1.0f;
m_glyph_max_height = 0;
m_glyph_max_above = 0;
m_glyph_max_below = 0;
m_face_ttf = new FaceTTF();
m_face_dpi = 40;
m_inverse_shaping = 1.0f;
Expand All @@ -86,6 +88,8 @@ FontWithFace::~FontWithFace()
void FontWithFace::init()
{
m_glyph_max_height = 0;
m_glyph_max_above = 0;
m_glyph_max_below = 0;
setDPI();
#ifndef SERVER_ONLY
if (GUIEngine::isNoGraphics())
Expand All @@ -99,6 +103,11 @@ void FontWithFace::init()
FT_Face cur_face = m_face_ttf->getFace(0);
font_manager->checkFTError(FT_Set_Pixel_Sizes(cur_face, 0, getDPI()),
"setting DPI");

int maxHeightAbove = (int)((cur_face->size->metrics.ascender +
(BEARING - 1)) / BEARING);
int maxHeightBelow = (int)((-cur_face->size->metrics.descender +
(BEARING - 1)) / BEARING);

for (int i = 32; i < 128; i++)
{
Expand All @@ -108,10 +117,26 @@ void FontWithFace::init()
font_manager->checkFTError(FT_Load_Glyph(cur_face, idx,
FT_LOAD_DEFAULT), "setting max height");

const int height = cur_face->glyph->metrics.height / BEARING;
if (height > m_glyph_max_height)
m_glyph_max_height = height;
font_manager->checkFTError(shapeOutline(&(cur_face->glyph->outline)),
"shaping outline");

// Height above and below the glyph baseline
FT_BBox bbox;
FT_Outline_Get_CBox(&(cur_face->glyph->outline), &bbox);
const int heightAbove = (int)((bbox.yMax + (BEARING - 1)) / BEARING);
const int heightBelow = (int)((-bbox.yMin + (BEARING - 1)) / BEARING);

if(heightBelow > maxHeightBelow) {
maxHeightBelow = heightBelow;
}

if (heightAbove > maxHeightAbove)
maxHeightAbove = heightAbove;
}

m_glyph_max_above = maxHeightAbove;
m_glyph_max_below = maxHeightBelow;
m_glyph_max_height = m_glyph_max_above + m_glyph_max_below;
#endif
reset();
} // init
Expand Down Expand Up @@ -324,11 +349,13 @@ void FontWithFace::insertGlyph(unsigned font_number, unsigned glyph_index)
(cur_face->glyph->advance.x / BEARING * scale_ratio);
a.bearing_x = (int)
(cur_face->glyph->metrics.horiBearingX / BEARING * scale_ratio);
const int cur_bearing_y =
(int)(cur_face->glyph->metrics.horiBearingY / BEARING * scale_ratio);
const int cur_height =
(int)(cur_face->glyph->metrics.height / BEARING * scale_ratio);
const int cur_offset_y = cur_height -
(int)(cur_face->glyph->metrics.horiBearingY / BEARING * scale_ratio);
a.offset_y = m_glyph_max_height - cur_height + cur_offset_y;
cur_bearing_y;
a.offset_y = m_glyph_max_above - cur_bearing_y;
a.offset_y_bt = -cur_offset_y;
a.spriteno = f.rectNumber;
m_face_ttf->insertFontArea(a, font_number, glyph_index);
Expand Down Expand Up @@ -506,15 +533,15 @@ core::dimension2d<u32> FontWithFace::getDimension(const core::stringw& text,
if (disableTextShaping())
{
return gui::getGlyphLayoutsDimension(text2GlyphsWithoutShaping(text),
m_font_max_height * scale, 1.0f/*inverse shaping*/, scale);
m_font_max_height * scale, m_glyph_max_height * scale, 1.0f/*inverse shaping*/, scale);
}

auto& gls = font_manager->getCachedLayouts(text);
if (gls.empty() && !text.empty())
font_manager->shape(StringUtils::wideToUtf32(text), gls);

return gui::getGlyphLayoutsDimension(gls,
m_font_max_height * scale, m_inverse_shaping, scale);
m_font_max_height * scale, m_glyph_max_height * scale, m_inverse_shaping, scale);
#endif
} // getDimension

Expand Down
4 changes: 4 additions & 0 deletions src/font/font_with_face.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class FontWithFace : public NoCopy
/** Used in top side bearing calculation. */
int m_glyph_max_height;

int m_glyph_max_above;

int m_glyph_max_below;

// ------------------------------------------------------------------------
/** Check characters to see if they are loaded in font, if not load them.
* For font that doesn't need lazy loading, nothing will be done.
Expand Down
2 changes: 1 addition & 1 deletion src/guiengine/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class TextMessage : public Message
gui::breakGlyphLayouts(m_gls, (float)max_width,
m_font->getInverseShaping(), m_font->getScale());
core::dimension2du dim = gui::getGlyphLayoutsDimension(m_gls,
m_font->getHeightPerLine(), m_font->getInverseShaping(),
m_font->getHeightPerLine(), m_font->getHeightPerGlyph(), m_font->getInverseShaping(),
m_font->getScale());

if ((int)dim.Height > m_font->getHeightPerLine() * 3)
Expand Down
13 changes: 13 additions & 0 deletions src/guiengine/scalable_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ s32 ScalableFont::getHeightPerLine() const
* m_font_settings->getScale();
} // getHeightPerLine

s32 ScalableFont::getHeightPerGlyph() const
{
const float scale = m_face->getNativeScalingFactor() *
m_font_settings->getScale();

const bool border = m_font_settings->useBlackBorder() ||
m_font_settings->useColoredBorder();
const bool thin_border = m_font_settings->useThinBorder();
const int thickness = border ? (thin_border ? 1 : 2) : 0;

return (m_face->getGlyphMaxHeight() + thickness * 2) * scale;
}

// ----------------------------------------------------------------------------
/** Convert text to glyph layouts for fast rendering with optional caching
* enabled.
Expand Down
2 changes: 2 additions & 0 deletions src/guiengine/scalable_font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ScalableFont : public IGUIFontBitmap
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
// ------------------------------------------------------------------------
virtual s32 getHeightPerLine() const;
virtual s32 getHeightPerGlyph() const;
// ------------------------------------------------------------------------
/** Calculates the index of the character in the text which is on a
* specific position. */
Expand Down Expand Up @@ -127,6 +128,7 @@ class ScalableFont : public IGUIFontBitmap
virtual f32 getInverseShaping() const;
// ------------------------------------------------------------------------
virtual s32 getFaceFontMaxHeight() const;

// ------------------------------------------------------------------------
virtual s32 getFaceGlyphMaxHeight() const;
};
Expand Down
10 changes: 5 additions & 5 deletions src/guiengine/widgets/CGUIEditBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ core::dimension2du CGUIEditBox::getTextDimension()
return core::dimension2du(0, 0);

return gui::getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(), font->getScale());
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(), font->getScale());
}


Expand Down Expand Up @@ -1222,7 +1222,7 @@ void CGUIEditBox::setTextRect(s32 line)

// get text dimension
d = gui::getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(), font->getScale());
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(), font->getScale());
// justification
switch (HAlign)
{
Expand Down Expand Up @@ -1339,14 +1339,14 @@ void CGUIEditBox::updateCursorDistance()
if (m_cursor_pos != 0)
{
m_cursor_distance = getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(),
font->getScale(), m_cursor_pos - 1).Width;
font->getHeightPerLine(), font->getHeightPerGlyph(),
font->getInverseShaping(), font->getScale(), m_cursor_pos - 1).Width;
}
else if ((m_glyph_layouts[0].flags & GLF_RTL_LINE) != 0)
{
// For rtl line the cursor in the begining is total width
m_cursor_distance = getGlyphLayoutsDimension(m_glyph_layouts,
font->getHeightPerLine(), font->getInverseShaping(),
font->getHeightPerLine(), font->getHeightPerGlyph(), font->getInverseShaping(),
font->getScale()).Width;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/states_screens/online/networking_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ void NetworkingLobby::updateChatScrollbar()
(unsigned)core::max_(1, (s32)m_text_bubble->getDimension().Width - scrollbar_width));
const float box_height = m_text_bubble->getDimension().Height;
s32 line_height = font->getHeightPerLine();
s32 glyph_height = font->getHeightPerGlyph();

if (box_height <= 0.0f || line_height <= 0)
return;
Expand All @@ -1435,7 +1436,7 @@ void NetworkingLobby::updateChatScrollbar()

// Calculate total height of all chat messages with correct line breaks
core::dimension2du total_dim = gui::getGlyphLayoutsDimension(
temp_layouts, line_height,
temp_layouts, line_height, glyph_height,
font->getInverseShaping(), font->getScale());

s32 total_height = total_dim.Height;
Expand Down
2 changes: 1 addition & 1 deletion src/states_screens/race_result_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ int RaceResultGUI::displayChallengeInfo(int x, int y, bool increase_density)
the_font->getScale());
irr::core::dimension2du dim =
irr::gui::getGlyphLayoutsDimension(best_while_slower_layout,
line_height,
line_height, line_height,
the_font->getInverseShaping(),
the_font->getScale());
text_color = special_color;
Expand Down