|
Post by alexfish on Mar 28, 2020 22:24:26 GMT 1
Dear Alex, I can see it taking shape. Don't rush - we're all self-isolated in any case - so any time is good. I wonder whether some of the widgets we did for the various canvases can be re-purposed - some of mine made use of cairo, if my memory serves be right (sliders, combo boxes and the like). With kind regards, vovchik Hi Vovchik Well that is basically what you are seeing above IE the scrolled window is drawn on a canvas/canvases IE all cairo + the pango layout as I mention the Gtk Entry box that was in has now gone, hence the text you are seeing is on that canvas/ as for the cursors these are calculated and drawn to the surface where the text is drawn it is definitely not a gtk edit Yet the menu is / but it fits the bill: BR Alex
|
|
|
Post by alexfish on Mar 29, 2020 23:06:36 GMT 1
Hi Vovchik Never a true word spoken have done block select in another tk but origin is 0 bottom , where as here we have 0 at top Now , not sure if any one has tried writing there own editor , and do a block select plus click the to call a pop up menu anyway now done and need to fallback to BaCon to test its buffer. A Picky text select block ready to copy BR Alex Attachments:
|
|
|
Post by alexfish on Apr 2, 2020 16:55:55 GMT 1
Hi All Between trying to find a new washing machine :: In a lock-down :: argh well that's another story and at arriving back here: Scrolling and selecting . it was important to get this bit out of the way at some stage and especially so with gtk , as I have now found out So after diving down the black-hole looks like I am out of it here is a screen shot of scrolled text and selecting the lines >> easy back soon BR Alex Attachments:
|
|
|
Post by alexfish on Apr 5, 2020 18:15:52 GMT 1
Hi All
Editor wise thing looking good
yet had a problem to resolve
'using baCon insert with utf8'
had to make a routine up to get the info from a string containing utf8
and run it passed the 'utf get info' can get the insertion point put a t as insert(str,2,'t')
LOCAL A$ = "€abcłd¹" TYPE STRING
PRINT A$
A$ = INSERT$(A$,4,"t")
PRINT A$
resutls
€abcłd¹ €tabcłd¹
the same bits need to be used for grabbing copy text a paste text
example of output of utf8 info bit to the right its the byte size
€abcłd¹
char :0: 3 char :1: 1 char :2: 1 char :3: 1 char :4: 2 char :5: 1 char :6: 2
now at back to full circle with poor-mans terminal + text editor
back soon
BR Alex
|
|
|
Post by vovchik on Apr 5, 2020 19:34:29 GMT 1
Dear Alex,
A word of thanks - you are doing all that dirty work with UTF8 bytes, to get appropriate string lengths. Take your time - we're all quarantined, in any case, and stay healthy.
With kind regards, vovchik
|
|
|
Post by alexfish on Apr 5, 2020 21:47:50 GMT 1
Hi Vovchik
Plenty Time
Well , the bits I be playing was to stream chars the original code is from a classic utf8 get code point. but intervened to pass the the byte size
but getting a compiler error in the while loop
cc -o utf utf.bac.o -lbacon -L. -lm Compiler error:
Description: file 'utf.bac' line 40: WHILE ((ss = next_utf8_char(ss, &character, &cdp)) != NULL) DO Cause: comparison between pointer and integer
whilst next_utf8_char can stay the same I wanted to baconize utf_info
any Ideas
BR Alex
the code so far
FUNCTION next_utf8_char(unsigned char *utf8, int *codepoint,int * ps) TYPE unsigned char * USEC int seqlen; int datalen = (int)strlen((const char *)utf8); unsigned char *p = utf8;
if (datalen < 1 || *utf8 == 0) { // End of string return NULL; } if (!(utf8[0] & 0x80)) { // 0xxxxxxx *codepoint = (wchar_t) utf8[0]; seqlen = 1; } else if ((utf8[0] & 0xE0) == 0xC0) { // 110xxxxx *codepoint = (int)(((utf8[0] & 0x1F) << 6) | (utf8[1] & 0x3F)); seqlen = 2; } else if ((utf8[0] & 0xF0) == 0xE0) { // 1110xxxx *codepoint = (int)(((utf8[0] & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6) | (utf8[2] & 0x3F)); seqlen = 3; } else { return NULL; // No code points this high here } *ps = seqlen; p += seqlen; return p;
END USEC
END FUNCTION
SUB utf_Info( const char *s) LOCAL character,ptr,cdp TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s USEC
while ((ss = next_utf8_char(ss, &character, &cdp)) != NULL) {
printf ("char : %d : %d\n", ptr , cdp); ptr++; }
END USEC END SUB
LOCAL A$ = "€abcłd¹" TYPE STRING
PRINT A$
A$ = INSERT$(A$,4,"t")
PRINT A$ utf_Info ("€abcłd¹")
|
|
|
Post by vovchik on Apr 5, 2020 22:39:13 GMT 1
Dear Alex,
It compiled for me and runs fine. My compile line is:
bacon -l -no-pie -o -fno-pie -o -Wno-implicit -o -Os -o -fdata-sections -o -ffunction-sections -o -Wl,--gc-sections -lmimalloc -l -s alex-cairo.bac
With kind regards, vovchik
|
|
|
Post by bigbass on Apr 6, 2020 1:20:40 GMT 1
Hello Alex
I had a similar (difficult) problem recently using WHILE and went a different road reduced it down and used REPEAT
seems to work for me hope its useful for you
Joe
FUNCTION next_utf8_char(unsigned char *utf8, int *codepoint,int * ps) TYPE unsigned char * USEC int seqlen; int datalen = (int)strlen((const char *)utf8); unsigned char *p = utf8;
if (datalen < 1 || *utf8 == 0) { // End of string return NULL; } if (!(utf8[0] & 0x80)) { // 0xxxxxxx *codepoint = (wchar_t) utf8[0]; seqlen = 1; } else if ((utf8[0] & 0xE0) == 0xC0) { // 110xxxxx *codepoint = (int)(((utf8[0] & 0x1F) << 6) | (utf8[1] & 0x3F)); seqlen = 2; } else if ((utf8[0] & 0xF0) == 0xE0) { // 1110xxxx *codepoint = (int)(((utf8[0] & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6) | (utf8[2] & 0x3F)); seqlen = 3; } else { return NULL; // No code points this high here } *ps = seqlen; p += seqlen; return p;
END USEC
END FUNCTION
SUB utf_Info( const char *s) LOCAL character,ptr,cdp TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s
REPEAT ss = next_utf8_char(ss, &character, &cdp) PRINT ptr , cdp FORMAT "char : %d : %d\n" INCR ptr UNTIL (ss == NULL)
END SUB
LOCAL A$ = "€abcłd¹" TYPE STRING
PRINT A$
A$ = INSERT$(A$,4,"t")
PRINT A$ utf_Info ("€abcłd¹")
terminal output I gained char7
€abcłd¹ €tabcłd¹ char : 0 : 3 char : 1 : 1 char : 2 : 1 char : 3 : 1 char : 4 : 2 char : 5 : 1 char : 6 : 2 char : 7 : 2
|
|
|
Post by alexfish on Apr 6, 2020 8:52:19 GMT 1
Thanks Joe
Now solved like so
SUB utf_Info( const char *s)
LOCAL character,ptr,cdp TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s
WHILE (ss ) DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN BREAK
END IF
PRINT "char :", ptr , ":" , cdp ' printf ("char : %d : %d\n", ptr , cdp); INCR ptr; WEND
END SUB
Can now turn the get info to insert char at position
BR Alex
|
|
|
Post by alexfish on Apr 6, 2020 10:52:24 GMT 1
Hi All
have put the bits in GetPostition of char
left all other bit as is
if position out of bounds with the string the insert will be end of string
BR Alex
so now have
ADDED Updated
FUNCTION next_utf8_char(unsigned char *utf8, int *codepoint,int * ps) TYPE unsigned char * USEC int seqlen; int datalen = (int)strlen((const char *)utf8); unsigned char *p = utf8;
if (datalen < 1 || *utf8 == 0) { // End of string return NULL; } if (!(utf8[0] & 0x80)) { // 0xxxxxxx *codepoint = (wchar_t) utf8[0]; seqlen = 1; } else if ((utf8[0] & 0xE0) == 0xC0) { // 110xxxxx *codepoint = (int)(((utf8[0] & 0x1F) << 6) | (utf8[1] & 0x3F)); seqlen = 2; } else if ((utf8[0] & 0xF0) == 0xE0) { // 1110xxxx *codepoint = (int)(((utf8[0] & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6) | (utf8[2] & 0x3F)); seqlen = 3; } else { return NULL; // No code points this high here } *ps = seqlen; p += seqlen; return p;
END USEC
END FUNCTION
SUB utf_Info( const char *s)
LOCAL character,ptr,cdp TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s
WHILE (ss ) DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN BREAK
END IF
PRINT "char :", ptr , ":" , cdp ' printf ("char : %d : %d\n", ptr , cdp); INCR ptr WEND
END SUB
FUNCTION GetPostition( const char * s,int pos) TYPE int
LOCAL character,ptr,cdp,ps TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s WHILE (ss ) DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN RETURN ps
END IF
INCR ps,cdp
IF ptr == pos THEN ' PRINT "char :", ptr , ":" , ps RETURN ps ' RETURN s$ BREAK END IF ' PRINT "char :", ptr , ":" , ps
INCR ptr WEND RETURN ps
END FUNCTION
FUNCTION InsertChar( const char * A,int pos ,STRING ch) TYPE const char * LOCAL x TYPE int LOCAL AB$ = (char*)A TYPE STRING LOCAL CP$ TYPE STRING CP$ = AB$
LOCAL sp$ TYPE STRING x= GetPostition(A,pos) sp$ = MID$(AB$,1,x) r$ = MID$(AB$,x+1) sp$ = sp$ & ch & r$ A = (const char*)sp$ RETURN A
END FUNCTION
' need to pas to a pas sequence .. how deep Do not know DECLARE A$ = "€łbcłd¹" TYPE const char * B$ = InsertChar(A$,4,"ß") PRINT B$ A$=B$ B$ = InsertChar(A$,4,"←") PRINT B$
can try code with "\n" in EG + show position 0 of insert = after first char
' need to pas to a pas sequence .. how deep Do not know DECLARE A$ = "€łb\ncłd¹" TYPE STRING B$ = InsertChar(A$,4,"ß") PRINT B$ A$=B$ B$ = InsertChar(A$,6,"←") PRINT B$
A$=B$ B$ = InsertChar(A$,0,"←") PRINT B$
or some long strings
DECLARE A$ = "€łb\ncłd¹" TYPE STRING B$ = InsertChar(A$,4,"ß") PRINT B$ A$=B$ B$ = InsertChar(A$,6,"←") PRINT B$
A$=B$ B$ = InsertChar(A$,0,"\nALL OF THIS\n") PRINT B$
|
|
|
Post by alexfish on Apr 6, 2020 13:43:12 GMT 1
Hi All
new method of utf string insert utf char
ABOVE
best I can do at present + should not overshoot if pos > len of string
have tested the A$ as BaCon STRING
DECLARE A$ = "€łbcłd¹" TYPE STRING so can use that instead ,
BR Alex
|
|
|
Post by bigbass on Apr 6, 2020 15:18:09 GMT 1
Hello Alex
yes, thanks . I see have to break out one before the loop ends
I like documenting bacon commands while porting and there are several ways to solve the same problem with the focus here the syntax when using WHILE/WEND or REPEAT/UNTIL
they are confirmed to be the same after this updated test
Joe
WHILE (ss ) DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN BREAK END IF
PRINT "char :", ptr , ":" , cdp INCR ptr WEND
€abcłd¹ €tabcłd¹ char :0:3 char :1:1 char :2:1 char :3:1 char :4:2 char :5:1 char :6:2 ==========================================================================
REPEAT ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN BREAK END IF PRINT ptr , cdp FORMAT "char : %d : %d\n" INCR ptr UNTIL (ss == NULL)
€abcłd¹ €tabcłd¹ char : 0 : 3 char : 1 : 1 char : 2 : 1 char : 3 : 1 char : 4 : 2 char : 5 : 1 char : 6 : 2
|
|
|
Post by alexfish on Apr 6, 2020 16:58:09 GMT 1
Hi Joe
Yes a bit like cart before the horse ...
anyway with all the bits in place with cart before the horse can now place the string anywhere
at beginning to the end of string , for end of string any value larger than string len will do
0 = at start of string
FUNCTION next_utf8_char(unsigned char *utf8, int *codepoint,int * ps) TYPE unsigned char * USEC int seqlen; int datalen = (int)strlen((const char *)utf8); unsigned char *p = utf8;
if (datalen < 1 || *utf8 == 0) { // End of string return NULL; } if (!(utf8[0] & 0x80)) { // 0xxxxxxx *codepoint = (wchar_t) utf8[0]; seqlen = 1; } else if ((utf8[0] & 0xE0) == 0xC0) { // 110xxxxx *codepoint = (int)(((utf8[0] & 0x1F) << 6) | (utf8[1] & 0x3F)); seqlen = 2; } else if ((utf8[0] & 0xF0) == 0xE0) { // 1110xxxx *codepoint = (int)(((utf8[0] & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6) | (utf8[2] & 0x3F)); seqlen = 3; } else { return NULL; // No code points this high here } *ps = seqlen; p += seqlen; return p;
END USEC
END FUNCTION
SUB utf_Info( const char *s)
LOCAL character,ptr,cdp TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s
WHILE (ss ) DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN BREAK
END IF
PRINT "char :", ptr , ":" , cdp ' printf ("char : %d : %d\n", ptr , cdp); INCR ptr WEND
END SUB
FUNCTION GetPostition( const char * s,int pos) TYPE int
LOCAL character,ptr,cdp,ps TYPE int LOCAL ss TYPE unsigned char * ss = (unsigned char *)s WHILE ss DO ss = next_utf8_char(ss, &character, &cdp) IF (ss == NULL) THEN RETURN ps
END IF
IF ptr == pos THEN ' PRINT "char :", ptr , ":" , ps RETURN ps ' RETURN s$ BREAK END IF ' PRINT "char :", ptr , ":" , ps INCR ps,cdp INCR ptr WEND RETURN ps
END FUNCTION
FUNCTION InsertChar( const char * A,int pos ,STRING ch) TYPE const char * LOCAL x TYPE int LOCAL AB$ = (char*)A TYPE STRING LOCAL CP$ TYPE STRING CP$ = AB$
LOCAL sp$ TYPE STRING x= GetPostition(A,pos) sp$ = MID$(AB$,1,x) r$ = MID$(AB$,x+1) sp$ = sp$ & ch & r$ A = (const char*)sp$ RETURN A
END FUNCTION
' need to pas to a pas sequence .. how deep Do not know DECLARE A$ = "€łb\ncłd¹" TYPE STRING B$ = InsertChar(A$,4,"ß") PRINT B$ A$=B$ B$ = InsertChar(A$,6,"←") PRINT B$
A$=B$ B$ = InsertChar(A$,0,"\nALL OF THIS\n") PRINT B$
A$=B$ B$ = InsertChar(A$,60,"\nBYE") PRINT B$
|
|
|
Post by alexfish on Apr 6, 2020 17:44:08 GMT 1
Hi All and to some of the why
typedef struct _GdkEventKey GdkEventKey;
struct _GdkEventKey { GdkEventType type; GdkWindow *window; gint8 send_event; guint32 time; guint state; guint keyval; gint length; gchar *string; };
in the app there is a callback to the keyboard
from the struct above can detect what key is pressed , keyval
most demo's put the keyval first , well here is a better way I say says he and the why
the gint length; gives the length of the string returned
and that length incudes the byte size as to what we have been looking at
if that that length is 0 the it is not a string
so if it has a length then gchar *string is the string + that string = whatever key it mapped language wise
IE the is no need for one's own key map
so for me yes I know what most of the keysyms are
hence the bits will detect if char and the use it
else :: check whick key has been press , esp arrow keys
when I say use the string first ,
from the bits shown , and have the insert point from the cursor pos then can directly inject the char at the keyboard event
Forgot :: another part of the why and why PANGO LAYOUT
pangolayout will detect the direction or orientation often seen on some editor's or terminals
The INPUT METHOD
and a further to the why , all the bits are rendered & drawn as image data
so at any stage should a use want a picky or print something
Got the Picky , yes
BR Alex
|
|
|
Post by alexfish on Apr 6, 2020 19:20:19 GMT 1
Hi All
as things stand I tried to insert a empty string
here looking for a bust at the init stages
DECLARE A$ = "" TYPE STRING B$ = InsertChar(A$,LEN(A$),"ß") PRINT B$ PRINT A$=B$ B$ = InsertChar(A$,LEN(A$),"←") PRINT B$ PRINT A$=B$ B$ = InsertChar(A$,LEN(A$),"ALL OF THIS") PRINT B$ PRINT A$=B$ B$ = InsertChar(A$,LEN(A$),"\nWhere I ¹²³ put it ") PRINT B$ PRINT A$=B$ B$ = InsertChar(A$,LEN(A$)," BYE ") PRINT B$
can have some fun with this
iterating through a loop
DECLARE A$ = "½¹²þø↓ŧ" TYPE STRING LOCAL curpos =2 TYPE int FOR t = 0 TO 5 B$ = InsertChar(A$,curpos+t,STR$(t)) A$ = B$ NEXT
PRINT B$
BR Alex
|
|