@@ -41,7 +41,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4141MCBlock::MCBlock (void )
4242{
4343 parent = NULL ;
44- flags = F_CLEAR;
44+ flags = F_CLEAR|F_HAS_UNICODE ;
4545 atts = NULL ;
4646 index = size = 0 ;
4747 width = 0 ;
@@ -605,15 +605,15 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
605605 }
606606
607607 const char *text;
608- text = parent -> gettext ();
608+ text = parent -> gettext_raw ();
609609
610610 // Fetch the first character of the next block
611611 int4 t_next_block_char;
612612 MCBlock *t_next_block;
613613 t_next_block = next ();
614614 if (t_next_block != parent -> getblocks ())
615615 {
616- if (t_next_block -> getsize () == 0 )
616+ if (t_next_block -> getbytesize () == 0 )
617617 t_next_block_char = -2 ;
618618 else if (t_next_block -> hasunicode ())
619619 t_next_block_char = *(uint2 *)&text[t_next_block -> index];
@@ -798,7 +798,7 @@ void MCBlock::split(uint2 p_index)
798798{
799799 MCBlock *bptr = new MCBlock (*this );
800800 uint2 newlength = size - (p_index - index);
801- bptr->setindex (parent -> gettext (), p_index, newlength);
801+ bptr->setbyteindex (parent -> gettext_raw (), p_index, newlength);
802802 size -= newlength;
803803 width = 0 ;
804804 // MW-2012-02-13: [[ Block Unicode ]] Only open the new block if the original
@@ -838,7 +838,7 @@ int2 MCBlock::gettabwidth(int2 x, const char *text, uint2 i)
838838 if (t_block -> getflag (F_HAS_TAB))
839839 {
840840 uint2 k;
841- k = t_block -> getindex () + t_block -> getsize ();
841+ k = t_block -> getbyteindex () + t_block -> getbytesize ();
842842 while (j < k && j < i)
843843 {
844844 if (t_block -> textcomparechar (&cptr[j], ' \t ' ))
@@ -847,7 +847,7 @@ int2 MCBlock::gettabwidth(int2 x, const char *text, uint2 i)
847847 }
848848 }
849849 else
850- j = t_block -> getindex () + t_block -> getsize ();
850+ j = t_block -> getbyteindex () + t_block -> getbytesize ();
851851 t_block = t_block -> next ();
852852 }
853853
@@ -926,7 +926,7 @@ int2 MCBlock::gettabwidth(int2 x, const char *text, uint2 i)
926926 }
927927}
928928
929- void MCBlock::drawstring (MCDC *dc, int2 x, int2 cx, int2 y, uint2 start, uint2 length, Boolean image, uint32_t style)
929+ void MCBlock::drawstring (MCDC *dc, int2 x, int2 cx, int2 y, findex_t start, findex_t length, Boolean image, uint32_t style)
930930{
931931 // MW-2012-02-16: [[ FontRefs ]] Fetch the font metrics we need to draw.
932932 int32_t t_ascent, t_descent;
@@ -937,7 +937,7 @@ void MCBlock::drawstring(MCDC *dc, int2 x, int2 cx, int2 y, uint2 start, uint2 l
937937 if (parent -> getvgrid ())
938938 {
939939 const char *t_text;
940- t_text = parent -> gettext ();
940+ t_text = parent -> gettext_raw ();
941941
942942 // MW-2012-02-09: [[ ParaStyles ]] Fetch the padding setting from the owning paragraph.
943943 // MW-2012-03-19: [[ Bug 10069 ]] Use the horiztonal padding value here.
@@ -1024,7 +1024,7 @@ void MCBlock::drawstring(MCDC *dc, int2 x, int2 cx, int2 y, uint2 start, uint2 l
10241024 {
10251025 const char *sptr;
10261026 uint2 size;
1027- sptr = parent -> gettext () + start;
1027+ sptr = parent -> gettext_raw () + start;
10281028 size = length;
10291029
10301030 // MW-2012-02-21: [[ LineBreak ]] Trim the block slightly if there is an explicit line break
@@ -1043,7 +1043,7 @@ void MCBlock::drawstring(MCDC *dc, int2 x, int2 cx, int2 y, uint2 start, uint2 l
10431043 if (flags & F_HAS_TAB)
10441044 {
10451045 const char *eptr;
1046- const char *tptr = parent->gettext ();
1046+ const char *tptr = parent->gettext_raw ();
10471047 while ((eptr = textstrchr (sptr, size, ' \t ' )) != NULL )
10481048 {
10491049 uint2 l = eptr - sptr;
@@ -1076,7 +1076,7 @@ void MCBlock::drawstring(MCDC *dc, int2 x, int2 cx, int2 y, uint2 start, uint2 l
10761076 }
10771077}
10781078
1079- void MCBlock::draw (MCDC *dc, int2 x, int2 cx, int2 y, uint2 si, uint2 ei, const char *tptr , uint2 pstyle, uint32_t p_border_flags)
1079+ void MCBlock::draw (MCDC *dc, int2 x, int2 cx, int2 y, findex_t si, findex_t ei, MCStringRef p_string , uint2 pstyle, uint32_t p_border_flags)
10801080{
10811081 if (flags & F_HAS_SHIFT)
10821082 y += atts->shift ;
@@ -1612,7 +1612,7 @@ void MCBlock::setbackcolor(const MCColor *newcolor)
16121612 }
16131613}
16141614
1615- void MCBlock::setindex (const char *sptr, uint2 i, uint2 l)
1615+ void MCBlock::setbyteindex (const char *sptr, uint2 i, uint2 l)
16161616{
16171617 index = i;
16181618 size = l;
@@ -1625,7 +1625,7 @@ void MCBlock::setindex(const char *sptr, uint2 i, uint2 l)
16251625 freeatts ();
16261626}
16271627
1628- void MCBlock::moveindex (const char *sptr, int2 ioffset, int2 loffset)
1628+ void MCBlock::movebyteindex (const char *sptr, int2 ioffset, int2 loffset)
16291629{
16301630 index += ioffset;
16311631 if (loffset != 0 )
@@ -1649,18 +1649,18 @@ uint2 MCBlock::getcursorx(int2 x, uint2 fi)
16491649 return getsubwidth (NULL , x, index, j);
16501650}
16511651
1652- uint2 MCBlock::getcursorindex (int2 x, int2 cx, Boolean chunk, Boolean last)
1652+ uint2 MCBlock::getcursorbyteindex (int2 x, int2 cx, Boolean chunk, Boolean last)
16531653{
16541654 // MW-2007-07-05: [[ Bug 5099 ]] If we have an image and are unicode, the char
16551655 // we replace is two bytes long
16561656 if (flags & F_HAS_IMAGE && atts->image != NULL )
16571657 if (chunk || cx < atts->image ->getrect ().width >> 1 )
16581658 return index;
16591659 else
1660- return index + (flags & F_HAS_UNICODE ? 2 : 1 ) ;
1660+ return index + 2 ;
16611661
16621662 uint2 i = index;
1663- const char *text = parent->gettext ();
1663+ const char *text = parent->gettext_raw ();
16641664 int2 cwidth;
16651665 uint2 tlen = 0 ;
16661666 uint2 twidth = 0 ;
@@ -1721,9 +1721,9 @@ uint2 MCBlock::getcursorindex(int2 x, int2 cx, Boolean chunk, Boolean last)
17211721 i += indexincrement (i);
17221722 }
17231723#endif
1724- if (i == index + size && last && (index + size != parent->gettextsize ()) && !hasunicode ())
1725- return i - indexdecrement (i);
1726- else
1724+ // if (i == index + size && last && (index + size != parent->gettextbytesize ()) && !hasunicode())
1725+ // return i - indexdecrement(i);
1726+ // else
17271727 return i;
17281728}
17291729
@@ -1735,8 +1735,8 @@ uint2 MCBlock::getsubwidth(MCDC *dc, int2 x, uint2 i, uint2 l)
17351735 return atts->image ->getrect ().width ;
17361736 else
17371737 {
1738- const char *tptr = parent->gettext ();
1739- const char *sptr = parent->gettext () + i;
1738+ const char *tptr = parent->gettext_raw ();
1739+ const char *sptr = parent->gettext_raw () + i;
17401740
17411741 // MW-2012-02-12: [[ Bug 10662 ]] If the last char is a VTAB then ignore it.
17421742 if (textcomparechar (sptr + l - getcharsize (), 11 ))
@@ -1791,7 +1791,7 @@ void MCBlock::reset()
17911791 width = 0 ;
17921792}
17931793
1794- void MCBlock::getindex (uint2 &i, uint2 &l)
1794+ void MCBlock::getbyteindex (uint2 &i, uint2 &l)
17951795{
17961796 i = index;
17971797 l = size;
@@ -1953,7 +1953,7 @@ uint2 MCBlock::indexincrement(uint2 tindex)
19531953
19541954 // Make sure we have the text pointer.
19551955 const char *thetext;
1956- thetext = parent->gettext ();
1956+ thetext = parent->gettext_raw ();
19571957
19581958 // Fetch the char
19591959 uint16_t *t_chars;
@@ -2009,7 +2009,7 @@ uint2 MCBlock::indexdecrement(uint2 tindex)
20092009
20102010 // Make sure we have the text pointer.
20112011 const char *thetext;
2012- thetext = parent->gettext ();
2012+ thetext = parent->gettext_raw ();
20132013
20142014 // Fetch the char pointer
20152015 uint16_t *t_chars;
@@ -2142,14 +2142,14 @@ uint4 MCBlock::getcharatindex(int4 p_index)
21422142 if (getflag (F_HAS_UNICODE))
21432143 {
21442144 if (t_block -> index + t_block -> size - p_index >= 2 )
2145- return *((uint2 *)(parent -> gettext () + p_index));
2145+ return *((uint2 *)(parent -> gettext_raw () + p_index));
21462146
2147- return parent -> gettext ()[p_index];
2147+ return parent -> gettext_raw ()[p_index];
21482148 }
21492149
21502150 // MW-2008-07-21: [[ Bug 6817 ]] Make sure we map the native encoded character
21512151 // to a Unicode codepoint.
2152- return MCUnicodeMapFromNative (parent -> gettext ()[p_index]);
2152+ return MCUnicodeMapFromNative (parent -> gettext_raw ()[p_index]);
21532153}
21542154
21552155MCBlock *MCBlock::retreatindex (uint2& p_index)
@@ -2376,11 +2376,11 @@ uint32_t MCBlock::measureattrs(void)
23762376bool MCBlock::getfirstlinebreak (uint2& r_index)
23772377{
23782378 char *t_break;
2379- t_break = textstrchr (parent -> gettext () + index, size, ' \x0B ' );
2379+ t_break = textstrchr (parent -> gettext_raw () + index, size, ' \x0B ' );
23802380 if (t_break == nil)
23812381 return false ;
23822382
2383- r_index = t_break - parent -> gettext ();
2383+ r_index = t_break - parent -> gettext_raw ();
23842384 advanceindex (r_index);
23852385
23862386 return true ;
@@ -2398,3 +2398,55 @@ bool MCBlock::imagechanged(MCImage *p_image, bool p_deleting)
23982398 return false ;
23992399}
24002400
2401+ void MCBlock::GetRange (findex_t &r_index, findex_t &r_length)
2402+ {
2403+ uint2 i, l;
2404+ getbyteindex (i, l);
2405+ r_index = i/sizeof (unichar_t );
2406+ r_length = l/sizeof (unichar_t );
2407+ }
2408+
2409+ findex_t MCBlock::GetOffset ()
2410+ {
2411+ findex_t i, l;
2412+ GetRange (i, l);
2413+ return i;
2414+ }
2415+
2416+ findex_t MCBlock::GetLength ()
2417+ {
2418+ findex_t i, l;
2419+ GetRange (i, l);
2420+ return l;
2421+ }
2422+
2423+ void MCBlock::SetRange (findex_t p_index, findex_t p_length)
2424+ {
2425+ setbyteindex (parent->gettext_raw (), p_index*sizeof (unichar_t ), p_length*sizeof (unichar_t ));
2426+ }
2427+
2428+ void MCBlock::MoveRange (findex_t p_index, findex_t p_length)
2429+ {
2430+ movebyteindex (parent->gettext_raw (), p_index*sizeof (unichar_t ), p_length*sizeof (unichar_t ));
2431+ }
2432+
2433+ MCBlock *MCBlock::AdvanceIndex (findex_t &x_index)
2434+ {
2435+ uint2 t_index = x_index * sizeof (unichar_t );
2436+ MCBlock *t_block = advanceindex (t_index);
2437+ x_index = t_index / sizeof (unichar_t );
2438+ return t_block;
2439+ }
2440+
2441+ MCBlock *MCBlock::RetreatIndex (findex_t &x_index)
2442+ {
2443+ uint2 t_index = x_index * sizeof (unichar_t );
2444+ MCBlock *t_block = retreatindex (t_index);
2445+ x_index = t_index / sizeof (unichar_t );
2446+ return t_block;
2447+ }
2448+
2449+ codepoint_t MCBlock::GetCodepointAtIndex (findex_t p_index) const
2450+ {
2451+ return parent->GetCodepointAtIndex ((index / sizeof (unichar_t )) + p_index);
2452+ }
0 commit comments