private int expandCompositChar(char[] dest,
                              int start,
                              int length,
                              int lacount,
                              int shapingMode) throws ArabicShapingException {

        int lenOptionsLamAlef = options & LAMALEF_MASK;
        int lenOptionsSeen = options & SEEN_MASK;
        int lenOptionsYehHamza = options & YEHHAMZA_MASK;
        boolean spaceNotFound = false;

        if (!isLogical && !spacesRelativeToTextBeginEnd) {
            switch (lenOptionsLamAlef) {
            case LAMALEF_BEGIN: lenOptionsLamAlef = LAMALEF_END; break;
            case LAMALEF_END: lenOptionsLamAlef = LAMALEF_BEGIN; break;
            default: break;
            }
        }

        if(shapingMode == 1){
            if(lenOptionsLamAlef == LAMALEF_AUTO){
                if(isLogical){
                    spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
                    if(spaceNotFound){
                        spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
                    }
                    if(spaceNotFound){
                        spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
                    }
                    if(spaceNotFound){
                        throw new ArabicShapingException("No spacefor lamalef");
                    }
                }else{
                    spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
                    if(spaceNotFound){
                        spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
                    }
                    if(spaceNotFound){
                        spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
                    }
                    if(spaceNotFound){
                        throw new ArabicShapingException("No spacefor lamalef");
                    }
                }
            }else if(lenOptionsLamAlef == LAMALEF_END){
                spaceNotFound = expandCompositCharAtEnd(dest, start, length, lacount);
                if(spaceNotFound){
                    throw new ArabicShapingException("No spacefor lamalef");
                }
            }else if(lenOptionsLamAlef == LAMALEF_BEGIN){
                spaceNotFound = expandCompositCharAtBegin(dest, start, length, lacount);
                if(spaceNotFound){
                    throw new ArabicShapingException("No spacefor lamalef");
                }
            }else if(lenOptionsLamAlef == LAMALEF_NEAR){
                spaceNotFound = expandCompositCharAtNear(dest, start, length,0,0,1);
                if(spaceNotFound){
                    throw new ArabicShapingException("No spacefor lamalef");
            }
            }else if(lenOptionsLamAlef == LAMALEF_RESIZE){
                for (int r = start + length, w = r + lacount; --r >= start;) {
                    char ch = dest[r];
                    if (isNormalizedLamAlefChar(ch)) {
                        dest[--w] = '\u0644';
                        dest[--w] = convertNormalizedLamAlef[ch - '\u065C'];
                    } else {
                        dest[--w] = ch;
                    }
                }
                length += lacount;
            }
            }else{
                if(lenOptionsSeen == SEEN_TWOCELL_NEAR){
                spaceNotFound = expandCompositCharAtNear(dest, start, length,0,1,0);
                if(spaceNotFound){
                    throw new ArabicShapingException("No space for Seen tail expansion");
                }
            }
            if(lenOptionsYehHamza == YEHHAMZA_TWOCELL_NEAR){
                spaceNotFound = expandCompositCharAtNear(dest, start, length,1,0,0);
                if(spaceNotFound){
                    throw new ArabicShapingException("No space for YehHamza expansion");
                }
            }
            }
        return length;
    }
private int expandCompositChar ( char [ ] dest , int start , int length , int lacount , int shapingMode ) throws ArabicShapingException { int lenOptionsLamAlef = options & LAMALEF_MASK ; int lenOptionsSeen = options & SEEN_MASK ; int lenOptionsYehHamza = options & YEHHAMZA_MASK ; boolean spaceNotFound = false ; if ( ! isLogical && ! spacesRelativeToTextBeginEnd ) { switch ( lenOptionsLamAlef ) { case LAMALEF_BEGIN : lenOptionsLamAlef = LAMALEF_END ; break ; case LAMALEF_END : lenOptionsLamAlef = LAMALEF_BEGIN ; break ; default : break ; } } if ( shapingMode == 1 ) { if ( lenOptionsLamAlef == LAMALEF_AUTO ) { if ( isLogical ) { spaceNotFound = expandCompositCharAtEnd ( dest , start , length , lacount ) ; if ( spaceNotFound ) { spaceNotFound = expandCompositCharAtBegin ( dest , start , length , lacount ) ; } if ( spaceNotFound ) { spaceNotFound = expandCompositCharAtNear ( dest , start , length , 0 , 0 , 1 ) ; } if ( spaceNotFound ) { throw new ArabicShapingException ( "No spacefor lamalef" ) ; } } else { spaceNotFound = expandCompositCharAtBegin ( dest , start , length , lacount ) ; if ( spaceNotFound ) { spaceNotFound = expandCompositCharAtEnd ( dest , start , length , lacount ) ; } if ( spaceNotFound ) { spaceNotFound = expandCompositCharAtNear ( dest , start , length , 0 , 0 , 1 ) ; } if ( spaceNotFound ) { throw new ArabicShapingException ( "No spacefor lamalef" ) ; } } } else if ( lenOptionsLamAlef == LAMALEF_END ) { spaceNotFound = expandCompositCharAtEnd ( dest , start , length , lacount ) ; if ( spaceNotFound ) { throw new ArabicShapingException ( "No spacefor lamalef" ) ; } } else if ( lenOptionsLamAlef == LAMALEF_BEGIN ) { spaceNotFound = expandCompositCharAtBegin ( dest , start , length , lacount ) ; if ( spaceNotFound ) { throw new ArabicShapingException ( "No spacefor lamalef" ) ; } } else if ( lenOptionsLamAlef == LAMALEF_NEAR ) { spaceNotFound = expandCompositCharAtNear ( dest , start , length , 0 , 0 , 1 ) ; if ( spaceNotFound ) { throw new ArabicShapingException ( "No spacefor lamalef" ) ; } } else if ( lenOptionsLamAlef == LAMALEF_RESIZE ) { for ( int r = start + length , w = r + lacount ; -- r >= start ; ) { char ch = dest [ r ] ; if ( isNormalizedLamAlefChar ( ch ) ) { dest [ -- w ] = 'ل' ; dest [ -- w ] = convertNormalizedLamAlef [ ch - 'ٜ' ] ; } else { dest [ -- w ] = ch ; } } length += lacount ; } } else { if ( lenOptionsSeen == SEEN_TWOCELL_NEAR ) { spaceNotFound = expandCompositCharAtNear ( dest , start , length , 0 , 1 , 0 ) ; if ( spaceNotFound ) { throw new ArabicShapingException ( "No space for Seen tail expansion" ) ; } } if ( lenOptionsYehHamza == YEHHAMZA_TWOCELL_NEAR ) { spaceNotFound = expandCompositCharAtNear ( dest , start , length , 1 , 0 , 0 ) ; if ( spaceNotFound ) { throw new ArabicShapingException ( "No space for YehHamza expansion" ) ; } } } return length ; }
/*
Name    : expandCompositChar
Function: LamAlef needs special handling as the LamAlef is
one character while expanding it will give two
characters Lam + Alef, so we need to expand the LamAlef
in near or far spaces according to the options the user
specifies or increase the buffer size.
Dest has enough room for the expansion if we are growing.
lamalef are normalized to the 'special characters'