Back to index

texmacs  1.0.7.15
aqua_utilities.mm
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : aqua_utilities.mm
00004 * DESCRIPTION: Utilities for Aqua
00005 * COPYRIGHT  : (C) 2007  Massimiliano Gubinelli
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "aqua_utilities.h"
00013 #include "dictionary.hpp"
00014 #include "converter.hpp"
00015 #include "analyze.hpp"
00016 
00017 NSRect to_nsrect(coord4 p)
00018 {
00019        float c = 1.0/PIXEL;
00020        return NSMakeRect(p.x1*c, -p.x4*c, (p.x3-p.x1)*c, (p.x4-p.x2)*c);
00021 }
00022 
00023 NSPoint to_nspoint(coord2 p)
00024 {
00025        float c = 1.0/PIXEL;
00026        return NSMakePoint(p.x1*c,-p.x2*c);
00027 }
00028 
00029 NSSize to_nssize(coord2 p)
00030 {
00031        float c = 1.0/PIXEL;
00032        return NSMakeSize(p.x1*c,p.x2*c);
00033 }
00034 
00035 coord4 from_nsrect(NSRect rect)
00036 {
00037        SI c1, c2, c3, c4;
00038        
00039        c1 = rect.origin.x*PIXEL;
00040        c2 = rect.origin.y*PIXEL;
00041        c3 = (rect.origin.x+rect.size.width)*PIXEL;
00042        c4 = (rect.origin.y+rect.size.height)*PIXEL;     
00043        return coord4 (c1, c2, c3, c4);
00044 }
00045 
00046 coord2 from_nspoint(NSPoint pt)
00047 {
00048        SI c1, c2;
00049        c1 = pt.x*PIXEL;
00050        c2 = -pt.y*PIXEL;
00051        return coord2 (c1,c2)       ;
00052 }
00053 
00054 coord2 from_nssize(NSSize s)
00055 {
00056        SI c1, c2;
00057        c1 = s.width*PIXEL;
00058        c2 = s.height*PIXEL;
00059        return coord2 (c1,c2)       ;
00060 }
00061 
00062 NSString *to_nsstring(string s)
00063 {
00064        char *p = as_charp(s);
00065        NSString *nss = [NSString stringWithCString:p encoding:NSUTF8StringEncoding];
00066        tm_delete_array (p); 
00067        return nss;
00068 }
00069 
00070 string from_nsstring(NSString *s)
00071 {
00072        const char *cstr = [s cStringUsingEncoding:NSUTF8StringEncoding];
00073        return utf8_to_cork(string((char*)cstr));
00074 }
00075 
00076 
00077 NSString *to_nsstring_utf8(string s)
00078 {
00079   s = cork_to_utf8 (s);
00080   char *p = as_charp(s);
00081   NSString *nss = [NSString stringWithCString:p encoding:NSUTF8StringEncoding];
00082   tm_delete_array (p);      
00083   return nss;
00084 }
00085 
00086 string
00087 aqua_translate (string s) {
00088   string out_lan= get_output_language ();
00089   return tm_var_encode (translate (s, "english", out_lan));
00090 }