# HG changeset patch # User Rik # Date 1443533372 25200 # Node ID ecca283644456cf6ec28b05e8af5530b5aafa9de # Parent 3aea4200da40e47f94802a5307d71a5515b29ec8 text.m: Allow '[]' to indicate blank line in multi-line cellstrings (bug #43017). * text.m: Convert any cell objects to cellstr objects which converts '[]' to ''. Add BIST tests for new behavior. diff -r 3aea4200da40 -r ecca28364445 scripts/plot/appearance/text.m --- a/scripts/plot/appearance/text.m Mon Sep 28 14:27:09 2015 -0700 +++ b/scripts/plot/appearance/text.m Tue Sep 29 06:29:32 2015 -0700 @@ -97,13 +97,13 @@ nt = numel (string); if (nx == 1) ## Single text object with one or more lines - string = {string}; + string = {cellstr(string)}; nt = 1; elseif (nx > 1 && nt == nx) ## Mutiple text objects with different strings else ## Mutiple text objects with same string - string = repmat ({string}, [nx, 1]); + string = repmat ({cellstr(string)}, [nx, 1]); nt = nx; endif @@ -271,13 +271,13 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! ## Single object with one line -%! h = text (0.5, 0.3, "single object with one line"); +%! h = text (0.5, 0.5, "single object with one line"); %! obs = get (h, "string"); %! assert (class (obs), "char"); %! assert (obs, "single object with one line"); %! %! ## Single object with multiple lines -%! h = text (0.5, 0.4, ["char row 1"; "char row 2"]); +%! h = text (0.5, 0.3, ["char row 1"; "char row 2"]); %! obs = get (h, "string"); %! assert (class (obs), "char"); %! assert (obs, ["char row 1"; "char row 2"]); @@ -290,28 +290,35 @@ %! assert (get (h(2), "string"), "two objects with same string"); %! %! ## Multiple objects with multiple lines -%! h = text ([0.1, 0.1], [0.3, 0.4], ["string1"; "string2"]); +%! h = text ([0.7, 0.7], [0.3, 0.4], ["string1"; "string2"]); %! assert (class (get (h(1), "string")), "char"); %! assert (class (get (h(2), "string")), "char"); %! assert (get (h(1), "string"), "string1"); %! assert (get (h(2), "string"), "string2"); %! %! ### Tests repeated with cell input ### +%! clf; %! %! ## Single object with one line -%! h = text (0.5, 0.3, {"single object with one line"}); +%! h = text (0.5, 0.5, {"single object with one line"}); %! obs = get (h, "string"); %! assert (class (obs), "cell"); %! assert (obs, {"single object with one line"}); %! %! ## Single object with multiple lines -%! h = text (0.5, 0.6, {"cell2str (1,1)", "cell2str (1,2)"; +%! h = text (0.5, 0.3, {"cell2str (1,1)", "cell2str (1,2)"; %! "cell2str (2,1)", "cell2str (2,2)"}); %! obs = get (h, "string"); %! assert (class (obs), "cell"); %! assert (obs, {"cell2str (1,1)"; "cell2str (2,1)"; %! "cell2str (1,2)"; "cell2str (2,2)"}); %! +%! ## Single object with multiple lines including empty cell +%! h = text (0.5, 0.9, {"Line1"; []; "Line3"}); +%! obs = get (h, "string"); +%! assert (class (obs), "cell"); +%! assert (obs, {"Line1"; ""; "Line3"}); +%! %! ## Multiple objects with single line %! h = text ([0.1, 0.1], [0.5, 0.6], {"two objects with same cellstr"}); %! assert (class (get (h(1), "string")), "cell"); @@ -320,6 +327,14 @@ %! assert (get (h(1), "string"), {"two objects with same cellstr"}); %! assert (get (h(2), "string"), {"two objects with same cellstr"}); %! +%! ## Multiple objects with same multi-line string which has empty cell +%! h = text ([0.7, 0.7], [0.3 0.5], {"Line1"; []; "Line3"}); +%! assert (class (get (h(1), "string")), "cell"); +%! assert (class (get (h(2), "string")), "cell"); +%! ## FIXME: is return value of cellstr, rather than string, Matlab-verified? +%! assert (get (h(1), "string"), {"Line1"; ""; "Line3"}); +%! assert (get (h(2), "string"), {"Line1"; ""; "Line3"}); +%! %! ## Multiple objects with multiple lines %! h = text ([0.1, 0.1], [0.7, 0.8], {"cellstr1", "cellstr2"}); %! ## FIXME: is return value really char in Matlab?