diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 749bf5fe0..fa0edf34e 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -36,14 +36,13 @@ $(ATTRIBUTES) showgrid = true, showticks = true, showtickmarks = true, - padding = 0.1, + padding = 0.0, ticks = Theme( - ranges_labels = (automatic, automatic), formatter = Formatters.plain, - gap = 3, + gap = 1, title_gap = 3, linewidth = (1, 1), @@ -56,9 +55,10 @@ $(ATTRIBUTES) align = ((:center, :top), (:right, :center)), font = lift(dim2, theme(scene, :font)), ), + tickmarks = Theme( - length = (3.0, 3.0), - linewidth = (1,1), + length = (1.0, 1.0), + linewidth = (1, 1), linecolor = ((:black, 0.4), (:black, 0.2)), linestyle = (nothing, nothing) ), @@ -383,6 +383,7 @@ function draw_titles( textcolor, textsize, rotation, align, font, title ) + tickspace_x = maximum(map(yticks) do tick str = last(tick) tick_bb = text_bb(str, to_font(tickfont[2]), tick_size[2]) @@ -411,7 +412,6 @@ function draw_titles( ) end end - if title !== nothing # TODO give title own text attributes push!( diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index 73d3a4bdd..26307645b 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -99,11 +99,10 @@ function boundingbox( text::String, position, textsize; font = "default", align = (:left, :bottom), rotation = 0.0 ) - boundingbox( + return boundingbox( text, position, textsize, to_font(font), to_align(align), to_rotation(rotation) ) - end # function boundingbox( @@ -138,6 +137,7 @@ end # return bb # end + function boundingbox( text::String, position, textsize, font, align, rotation, model = Mat4f0(I) @@ -157,12 +157,20 @@ function boundingbox( ctext_state = iterate(text, text_state) # TODO fix center + align + rotation if c != '\r' - pos = if pos_per_char - to_ndim(Vec3f0, position[i], 0.0) + posnd = if pos_per_char + position[i] else last_pos = calc_position(last_pos, Point2f0(0, 0), atlas, c, font, scale) - start_pos3d .+ (rotation * to_ndim(Vec3f0, last_pos, 0.0)) + advance_x, advance_y = glyph_advance!(atlas, c, font, scale) + without_advance = if c == '\n' + # advance doesn't get added for newlines + last_pos + else + last_pos .- Point2f0(advance_x, 0) + end + start_pos3d .+ (rotation * to_ndim(Vec3f0, without_advance, 0.0)) end + pos = to_ndim(Vec3f0, posnd, 0.0) s = glyph_scale!(atlas, c, font, scale) srot = rotation * to_ndim(Vec3f0, s, 0.0) bb = GeometryTypes.update(bb, pos) diff --git a/src/theming.jl b/src/theming.jl index 755c50fa5..224604863 100644 --- a/src/theming.jl +++ b/src/theming.jl @@ -44,7 +44,7 @@ const minimal_default = Attributes( axis_type = automatic, camera = automatic, limits = automatic, - padding = Vec3f0(0.1), + padding = Vec3f0(0.05), raw = false ) diff --git a/src/utilities/texture_atlas.jl b/src/utilities/texture_atlas.jl index fca342086..cd0f5bdd1 100644 --- a/src/utilities/texture_atlas.jl +++ b/src/utilities/texture_atlas.jl @@ -290,12 +290,23 @@ function calc_position(glyphs, start_pos, scales, fonts, atlas) positions = zeros(Point2f0, length(glyphs)) last_pos = Point2f0(start_pos) s, f = iter_or_array(scales), iter_or_array(fonts) - c1 = first(glyphs) - for (i, (c2, scale, font)) in enumerate(zip(glyphs, s, f)) - c2 == '\r' && continue # stupid windows! - b = glyph_bearing!(atlas, c2, font, scale) - positions[i] = last_pos .+ b - last_pos = calc_position(last_pos, start_pos, atlas, c2, font, scale) + iter = enumerate(zip(glyphs, s, f)) + next = iterate(iter) + if next !== nothing + (i, (char, scale, font)), state = next + first_bearing = glyph_bearing!(atlas, char, font, scale) + while next !== nothing + (i, (char, scale, font)), state = next + next = iterate(iter, state) + char == '\r' && continue # stupid windows! + # we draw the glyph at the last position we calculated + bearing = glyph_bearing!(atlas, char, font, scale) + # we substract the first bearing, since we want to start at + # startposition without any additional offset! + positions[i] = last_pos .+ bearing .- first_bearing + # then we add the advance for the next glyph to start + last_pos = calc_position(last_pos, start_pos, atlas, char, font, scale) + end end return positions end diff --git a/test/runtests.jl b/test/runtests.jl index 10c1332e2..51ccf0b2f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,6 @@ using Test using GLMakie # Download reference images from master -MakieGallery.current_ref_version[] = "master" const MINIMAL = get(ENV, "ABSTRACTPLOTTING_MINIMAL", "false") @@ -35,7 +34,7 @@ include("shorthands.jl") @test scene[Axis].ticks.title_gap[] == 3 scene[Axis].ticks.title_gap = 4 @test scene[Axis].ticks.title_gap[] == 4 - @test scene[Axis].tickmarks.length[] == (3, 3) + @test scene[Axis].tickmarks.length[] == (1, 1) end