mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Minor tidying-up.
This commit is contained in:
parent
b118dd6916
commit
ccc89aaae9
2 changed files with 37 additions and 57 deletions
|
|
@ -55,33 +55,30 @@ PositionedGlyph& PositionedGlyph::operator= (const PositionedGlyph& other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
static inline void drawGlyphWithFont (const Graphics& g, int glyph, const Font& font, const AffineTransform& t)
|
||||
{
|
||||
LowLevelGraphicsContext& context = g.getInternalContext();
|
||||
context.setFont (font);
|
||||
context.drawGlyph (glyph, t);
|
||||
}
|
||||
|
||||
void PositionedGlyph::draw (const Graphics& g) const
|
||||
{
|
||||
if (! isWhitespace())
|
||||
{
|
||||
LowLevelGraphicsContext& context = g.getInternalContext();
|
||||
context.setFont (font);
|
||||
context.drawGlyph (glyph, AffineTransform::translation (x, y));
|
||||
}
|
||||
drawGlyphWithFont (g, glyph, font, AffineTransform::translation (x, y));
|
||||
}
|
||||
|
||||
void PositionedGlyph::draw (const Graphics& g, const AffineTransform& transform) const
|
||||
{
|
||||
if (! isWhitespace())
|
||||
{
|
||||
LowLevelGraphicsContext& context = g.getInternalContext();
|
||||
context.setFont (font);
|
||||
context.drawGlyph (glyph, AffineTransform::translation (x, y).followedBy (transform));
|
||||
}
|
||||
drawGlyphWithFont (g, glyph, font, AffineTransform::translation (x, y).followedBy (transform));
|
||||
}
|
||||
|
||||
void PositionedGlyph::createPath (Path& path) const
|
||||
{
|
||||
if (! isWhitespace())
|
||||
{
|
||||
Typeface* const t = font.getTypeface();
|
||||
|
||||
if (t != nullptr)
|
||||
if (Typeface* const t = font.getTypeface())
|
||||
{
|
||||
Path p;
|
||||
t->getOutlineForGlyph (glyph, p);
|
||||
|
|
@ -96,9 +93,7 @@ bool PositionedGlyph::hitTest (float px, float py) const
|
|||
{
|
||||
if (getBounds().contains (px, py) && ! isWhitespace())
|
||||
{
|
||||
Typeface* const t = font.getTypeface();
|
||||
|
||||
if (t != nullptr)
|
||||
if (Typeface* const t = font.getTypeface())
|
||||
{
|
||||
Path p;
|
||||
t->getOutlineForGlyph (glyph, p);
|
||||
|
|
@ -625,25 +620,16 @@ void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
|
|||
{
|
||||
const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
|
||||
| Justification::horizontallyCentred)));
|
||||
float deltaX = 0.0f;
|
||||
float deltaX = 0.0f, deltaY = 0.0f;
|
||||
|
||||
if (justification.testFlags (Justification::horizontallyJustified))
|
||||
deltaX = x - bb.getX();
|
||||
else if (justification.testFlags (Justification::horizontallyCentred))
|
||||
deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
|
||||
else if (justification.testFlags (Justification::right))
|
||||
deltaX = (x + width) - bb.getRight();
|
||||
else
|
||||
deltaX = x - bb.getX();
|
||||
if (justification.testFlags (Justification::horizontallyJustified)) deltaX = x - bb.getX();
|
||||
else if (justification.testFlags (Justification::horizontallyCentred)) deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
|
||||
else if (justification.testFlags (Justification::right)) deltaX = x + width - bb.getRight();
|
||||
else deltaX = x - bb.getX();
|
||||
|
||||
float deltaY = 0.0f;
|
||||
|
||||
if (justification.testFlags (Justification::top))
|
||||
deltaY = y - bb.getY();
|
||||
else if (justification.testFlags (Justification::bottom))
|
||||
deltaY = (y + height) - bb.getBottom();
|
||||
else
|
||||
deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
|
||||
if (justification.testFlags (Justification::top)) deltaY = y - bb.getY();
|
||||
else if (justification.testFlags (Justification::bottom)) deltaY = y + height - bb.getBottom();
|
||||
else deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
|
||||
|
||||
moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
|
||||
|
||||
|
|
@ -718,6 +704,21 @@ void GlyphArrangement::spreadOutLine (const int start, const int num, const floa
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
inline void GlyphArrangement::drawGlyphUnderline (const Graphics& g, const PositionedGlyph& pg,
|
||||
const int i, const AffineTransform& transform) const
|
||||
{
|
||||
const float lineThickness = (pg.font.getDescent()) * 0.3f;
|
||||
|
||||
float nextX = pg.x + pg.w;
|
||||
|
||||
if (i < glyphs.size() - 1 && glyphs.getReference (i + 1).y == pg.y)
|
||||
nextX = glyphs.getReference (i + 1).x;
|
||||
|
||||
Path p;
|
||||
p.addRectangle (pg.x, pg.y + lineThickness * 2.0f, nextX - pg.x, lineThickness);
|
||||
g.fillPath (p, transform);
|
||||
}
|
||||
|
||||
void GlyphArrangement::draw (const Graphics& g) const
|
||||
{
|
||||
for (int i = 0; i < glyphs.size(); ++i)
|
||||
|
|
@ -725,17 +726,7 @@ void GlyphArrangement::draw (const Graphics& g) const
|
|||
const PositionedGlyph& pg = glyphs.getReference(i);
|
||||
|
||||
if (pg.font.isUnderlined())
|
||||
{
|
||||
const float lineThickness = (pg.font.getDescent()) * 0.3f;
|
||||
|
||||
float nextX = pg.x + pg.w;
|
||||
|
||||
if (i < glyphs.size() - 1 && glyphs.getReference (i + 1).y == pg.y)
|
||||
nextX = glyphs.getReference (i + 1).x;
|
||||
|
||||
g.fillRect (pg.x, pg.y + lineThickness * 2.0f,
|
||||
nextX - pg.x, lineThickness);
|
||||
}
|
||||
drawGlyphUnderline (g, pg, i, AffineTransform::identity);
|
||||
|
||||
pg.draw (g);
|
||||
}
|
||||
|
|
@ -748,19 +739,7 @@ void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform
|
|||
const PositionedGlyph& pg = glyphs.getReference(i);
|
||||
|
||||
if (pg.font.isUnderlined())
|
||||
{
|
||||
const float lineThickness = (pg.font.getDescent()) * 0.3f;
|
||||
|
||||
float nextX = pg.x + pg.w;
|
||||
|
||||
if (i < glyphs.size() - 1 && glyphs.getReference (i + 1).y == pg.y)
|
||||
nextX = glyphs.getReference (i + 1).x;
|
||||
|
||||
Path p;
|
||||
p.addLineSegment (Line<float> (pg.x, pg.y + lineThickness * 2.0f,
|
||||
nextX, pg.y + lineThickness * 2.0f), lineThickness);
|
||||
g.fillPath (p, transform);
|
||||
}
|
||||
drawGlyphUnderline (g, pg, i, transform);
|
||||
|
||||
pg.draw (g, transform);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ private:
|
|||
int fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font&,
|
||||
const Justification&, float minimumHorizontalScale);
|
||||
void spreadOutLine (int start, int numGlyphs, float targetWidth);
|
||||
void drawGlyphUnderline (const Graphics&, const PositionedGlyph&, int, const AffineTransform&) const;
|
||||
|
||||
JUCE_LEAK_DETECTOR (GlyphArrangement)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue