summaryrefslogtreecommitdiff
path: root/modules/graphics/macros/xstringl.sci
blob: 12ab3781803f7039c1c575c528c8387fe158b1ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

//=======================================================================
// File   : xstringl.sci
// Desc   : Compute the bounding rectangle of a text
//          (old version of stringbox)
//======================================================================

function [rect] = xstringl( varargin )

    // the call is rect=xstringl(x,y,str,[fontId,fontSize])

    [lhs,rhs] = argn(0) ;
    listArg = varargin ;

    // rect = xstringl(x,y,str,[fontId,fontSize])

    select rhs,
    case 3 then
        // stringbox(str, x, y)
        corners = stringbox(listArg (3), listArg (1), listArg (2));
    case 4 then
        // stringbox(str, x, y, angle = 0, fontId)
        corners = stringbox(listArg (3), listArg (1), listArg (2), 0, listArg (4));
    case 5 then
        // stringbox(str, x, y, angle = 0, fontId, fontSize);
        corners = stringbox(listArg (3), listArg (1), listArg (2), 0, listArg (4), listArg (5));
    else
        // incorrect number of input argmuments
        error(msprintf(gettext("%s: Wrong number of input argument(s): %d to %d expected."), "xstringl", 3, 5));
        return ;
    end;

    // convert corners into position and size
    // position, upper-left point
    rect(1) = corners (1,2); // x
    rect(2) = corners (2,2); // y

    // size width, height
    rect(3) = abs(corners(1,3) - corners(1,1));
    rect(4) = abs(corners(2,3) - corners(2,1));

endfunction