alignment function
This commit is contained in:
parent
e980fe8296
commit
fe2e6b32e7
2 changed files with 38 additions and 17 deletions
|
@ -13,31 +13,49 @@
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: DrawUtil.cc,v 1.9 2002/11/25 14:00:20 fluxgen Exp $
|
// $Id: DrawUtil.cc,v 1.10 2002/11/26 15:50:46 fluxgen Exp $
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif //HAVE_CONFIG_H
|
|
||||||
|
|
||||||
#include "DrawUtil.hh"
|
#include "DrawUtil.hh"
|
||||||
#include "StringUtil.hh"
|
|
||||||
#include "i18n.hh"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace DrawUtil {
|
namespace DrawUtil {
|
||||||
|
|
||||||
|
int doAlignment(int max_width, int bevel, Font::FontJustify justify,
|
||||||
|
const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen) {
|
||||||
|
|
||||||
|
if (text == 0 || textlen == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int l = font.textWidth(text, textlen) + bevel;
|
||||||
|
size_t dlen = textlen;
|
||||||
|
int dx = bevel;
|
||||||
|
if (l > max_width) {
|
||||||
|
for (; dlen > 0; dlen--) {
|
||||||
|
l = font.textWidth(text, dlen) + bevel;
|
||||||
|
if (l<=max_width)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newlen = dlen;
|
||||||
|
|
||||||
|
switch (justify) {
|
||||||
|
case DrawUtil::Font::RIGHT:
|
||||||
|
dx = max_width - l - bevel;
|
||||||
|
break;
|
||||||
|
case DrawUtil::Font::CENTER:
|
||||||
|
dx = (max_width - l)/2;
|
||||||
|
break;
|
||||||
|
case DrawUtil::Font::LEFT:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dx;
|
||||||
|
}
|
||||||
|
|
||||||
}; //end namespace DrawUtil
|
}; //end namespace DrawUtil
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: DrawUtil.hh,v 1.8 2002/11/25 14:00:20 fluxgen Exp $
|
// $Id: DrawUtil.hh,v 1.9 2002/11/26 15:45:48 fluxgen Exp $
|
||||||
|
|
||||||
#ifndef DRAWUTIL_HH
|
#ifndef DRAWUTIL_HH
|
||||||
#define DRAWUTIL_HH
|
#define DRAWUTIL_HH
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include "Font.hh"
|
||||||
|
|
||||||
namespace DrawUtil {
|
namespace DrawUtil {
|
||||||
// note: obsolete!
|
// note: obsolete!
|
||||||
|
@ -37,6 +38,8 @@ namespace DrawUtil {
|
||||||
FontJustify justify;
|
FontJustify justify;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int doAlignment(int max_width, int bevel, Font::FontJustify justify,
|
||||||
|
const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen);
|
||||||
}; //end namespace DrawUtil
|
}; //end namespace DrawUtil
|
||||||
|
|
||||||
#endif //DRAWUTIL_HH
|
#endif //DRAWUTIL_HH
|
||||||
|
|
Loading…
Reference in a new issue