Changeset 30:1e14cb29290a

Show
Ignore:
Timestamp:
01/27/08 20:37:23 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

TextLayout?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/dwthelper/utils.d

    r28 r30  
    9494 
    9595public wchar[] toCharArray( char[] str ){ 
    96     return StrToWCHARs( str ); 
     96    return toString16( str ); 
    9797} 
    9898 
  • dwt/graphics/TextLayout.d

    r29 r30  
    3232import tango.text.convert.Format; 
    3333import dwt.dwthelper.utils; 
     34import dwt.dwthelper.System; 
    3435 
    3536/** 
     
    6566    StyleItem[][] runs; 
    6667    int[] lineOffset, lineY, lineWidth; 
    67     int mLangFontLink2; 
     68    void* mLangFontLink2; 
    6869 
    6970    static const wchar LTR_MARK = '\u200E', RTL_MARK = '\u200F'; 
     
    9495        /*Place info (malloc when the run is placed) */ 
    9596        int* advances; 
    96         int* goffsets; 
    97         int* width; 
    98         int* ascent; 
    99         int* descent; 
    100         int* leading; 
    101         int* x; 
     97        GOFFSET* goffsets; 
     98        int width; 
     99        int ascent; 
     100        int descent; 
     101        int leading; 
     102        int x; 
    102103 
    103104        /* Justify info (malloc during computeRuns) */ 
     
    107108        SCRIPT_LOGATTR* psla; 
    108109 
    109         int* fallbackFont; 
     110        HFONT fallbackFont; 
    110111 
    111112    void free() { 
     
    146147        } 
    147148        if (fallbackFont !is null) { 
    148             if (mLangFontLink2 !is 0) { 
     149            if (mLangFontLink2 !is null) { 
    149150                /* ReleaseFont() */ 
    150                 OS.VtblCall(8, mLangFontLink2, fallbackFont); 
     151                OS.VtblCall(8, mLangFontLink2, cast(int)fallbackFont); 
    151152            } 
    152153            fallbackFont = null; 
    153154        } 
    154         width = ascent = descent = x = 0; 
     155        width = 0; 
     156        ascent = 0; 
     157        descent = 0; 
     158        x = 0; 
    155159        lineBreak = softBreak = false; 
    156160    } 
     
    185189    styles[1] = new StyleItem(); 
    186190    text = ""; //$NON-NLS-1$ 
    187     int[] ppv = new int[1]
    188     OS.OleInitialize(0); 
    189     if (OS.CoCreateInstance(CLSID_CMultiLanguage, 0, OS.CLSCTX_INPROC_SERVER, IID_IMLangFontLink2, ppv) is OS.S_OK) { 
    190         mLangFontLink2 = ppv[0]
     191    void* ppv
     192    OS.OleInitialize(null); 
     193    if (OS.CoCreateInstance(CLSID_CMultiLanguage.ptr, null, OS.CLSCTX_INPROC_SERVER, IID_IMLangFontLink2.ptr, cast(void*)&ppv) is OS.S_OK) { 
     194        mLangFontLink2 = ppv
    191195    } 
    192196    if (device.tracking) device.new_Object(this); 
     
    194198 
    195199void breakRun(StyleItem run) { 
    196     if (run.psla !is 0) return; 
    197     char[] chars = new char[run.length]; 
    198     segmentsText.getChars(run.start, run.start + run.length, chars, 0); 
    199     int hHeap = OS.GetProcessHeap(); 
    200     run.psla = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length); 
    201     if (run.psla is 0) DWT.error(DWT.ERROR_NO_HANDLES); 
    202     OS.ScriptBreak(chars, chars.length, run.analysis, run.psla); 
    203 
    204  
    205 void checkItem (int hDC, StyleItem item) { 
    206     if (item.fallbackFont !is 0) { 
     200    if (run.psla !is null) return; 
     201    wchar[] chars = StrToWCHARs( segmentsText[ run.start .. run.start + run.length ] ); 
     202    auto hHeap = OS.GetProcessHeap(); 
     203    run.psla = cast(SCRIPT_LOGATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length); 
     204    if (run.psla is null) DWT.error(DWT.ERROR_NO_HANDLES); 
     205    OS.ScriptBreak(chars.ptr, chars.length, &run.analysis, run.psla); 
     206
     207 
     208void checkItem (HDC hDC, StyleItem item) { 
     209    if (item.fallbackFont !is null) { 
    207210        /* 
    208211        * Feature in Windows. The fallback font returned by the MLang service 
     
    213216        */ 
    214217        LOGFONT logFont; 
    215         if (OS.GetObject(item.fallbackFont, LOGFONT.sizeof, &logFont) is 0) { 
     218        if (OS.GetObject( item.fallbackFont, LOGFONT.sizeof, &logFont) is 0) { 
    216219            item.free(); 
    217220            OS.SelectObject(hDC, getItemFont(item)); 
     
    231234void computeRuns (GC gc) { 
    232235    if (runs !is null) return; 
    233     int hDC = gc !is null ? gc.handle : device.internal_new_GC(null); 
    234     int srcHdc = OS.CreateCompatibleDC(hDC); 
     236    auto hDC = gc !is null ? gc.handle : device.internal_new_GC(null); 
     237    auto srcHdc = OS.CreateCompatibleDC(hDC); 
    235238    allRuns = itemize(); 
    236239    for (int i=0; i<allRuns.length - 1; i++) { 
     
    239242        shape(srcHdc, run); 
    240243    } 
    241     SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR()
    242     SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES()
     244    SCRIPT_LOGATTR* logAttr
     245    SCRIPT_PROPERTIES* properties
    243246    int lineWidth = indent, lineStart = 0, lineCount = 1; 
    244247    for (int i=0; i<allRuns.length - 1; i++) { 
     
    289292                piDx[0] = run.width; 
    290293            } else { 
    291                 OS.ScriptGetLogicalWidths(run.analysis, run.length, run.glyphCount, run.advances, run.clusters, run.visAttrs, piDx); 
     294                OS.ScriptGetLogicalWidths(&run.analysis, run.length, run.glyphCount, run.advances, run.clusters, run.visAttrs, piDx.ptr); 
    292295            } 
    293296            int width = 0, maxWidth = wrapWidth - lineWidth; 
     
    300303                breakRun(run); 
    301304                while (start >= 0) { 
    302                     OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
     305                    logAttr = run.psla + start; 
     306                    //OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
    303307                    if (logAttr.fSoftBreak || logAttr.fWhiteSpace) break; 
    304308                    start--; 
     
    312316                if (start is 0 && i !is lineStart && !run.tab) { 
    313317                    if (logAttr.fSoftBreak && !logAttr.fWhiteSpace) { 
    314                         OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof); 
     318                        properties = device.scripts[run.analysis.eScript]; 
     319                        //OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof); 
    315320                        int langID = properties.langid; 
    316321                        StyleItem pRun = allRuns[i - 1]; 
    317                         OS.MoveMemory(properties, device.scripts[pRun.analysis.eScript], SCRIPT_PROPERTIES.sizeof); 
     322                        //OS.MoveMemory(properties, device.scripts[pRun.analysis.eScript], SCRIPT_PROPERTIES.sizeof); 
    318323                        if (properties.langid is langID || langID is OS.LANG_NEUTRAL || properties.langid is OS.LANG_NEUTRAL) { 
    319324                            breakRun(pRun); 
    320                             OS.MoveMemory(logAttr, pRun.psla + ((pRun.length - 1) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
     325                            logAttr = pRun.psla + (pRun.length - 1); 
     326                            //OS.MoveMemory(logAttr, pRun.psla + ((pRun.length - 1) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
    321327                            if (!logAttr.fWhiteSpace) start = -1; 
    322328                        } 
     
    336342            breakRun(run); 
    337343            while (start < run.length) { 
    338                 OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
     344                logAttr = run.psla + start; 
     345                //OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
    339346                if (!logAttr.fWhiteSpace) break; 
    340347                start++; 
     
    370377    } 
    371378    lineWidth = 0; 
    372     runs = new StyleItem[lineCount][]
     379    runs = new StyleItem[][](lineCount)
    373380    lineOffset = new int[lineCount + 1]; 
    374381    lineY = new int[lineCount + 1]; 
     
    408415                    } 
    409416                } 
    410                 int hHeap = OS.GetProcessHeap(); 
     417                auto hHeap = OS.GetProcessHeap(); 
    411418                int newLineWidth = 0; 
    412419                for (int j = 0; j < runs[line].length; j++) { 
     
    414421                    int iDx = item.width * wrapWidth / lineWidth; 
    415422                    if (iDx !is item.width) { 
    416                         item.justify = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, item.glyphCount * 4); 
    417                         if (item.justify is 0) DWT.error(DWT.ERROR_NO_HANDLES); 
     423                        item.justify = cast(int*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, item.glyphCount * 4); 
     424                        if (item.justify is null) DWT.error(DWT.ERROR_NO_HANDLES); 
    418425                        OS.ScriptJustify(item.visAttrs, item.advances, item.glyphCount, iDx - item.width, 2, item.justify); 
    419426                        item.width = iDx; 
     
    447454        } 
    448455    } 
    449     if (srcHdc !is 0) OS.DeleteDC(srcHdc); 
     456    if (srcHdc !is null) OS.DeleteDC(srcHdc); 
    450457    if (gc is null) device.internal_dispose_GC(hDC, null); 
    451458} 
     
    467474    lineY = null; 
    468475    lineWidth = null; 
    469     if (mLangFontLink2 !is 0) { 
     476    if (mLangFontLink2 !is null) { 
    470477        /* Release() */ 
    471478        OS.VtblCall(2, mLangFontLink2); 
    472         mLangFontLink2 = 0
     479        mLangFontLink2 = null
    473480    } 
    474481    OS.OleUninitialize(); 
     
    553560    if (selectionForeground !is null && selectionForeground.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    554561    if (selectionBackground !is null && selectionBackground.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    555     int length = text.length()
     562    int length = text.length
    556563    if (length is 0 && flags is 0) return; 
    557     int hdc = gc.handle; 
     564    auto hdc = gc.handle; 
    558565    Rectangle clip = gc.getClipping(); 
    559566    GCData data = gc.data; 
    560     int gdipGraphics = data.gdipGraphics; 
    561     int foreground = data.foreground; 
    562     int alpha = data.alpha; 
    563     bool gdip = gdipGraphics !is 0 && (alpha !is 0xFF || data.foregroundPattern !is null); 
    564     int clipRgn = 0
     567    auto gdipGraphics = data.gdipGraphics; 
     568    auto foreground = data.foreground; 
     569    auto alpha = data.alpha; 
     570    bool gdip = gdipGraphics !is null && (alpha !is 0xFF || data.foregroundPattern !is null); 
     571    HRGN clipRgn
    565572    float[] lpXform = null; 
    566     Rect gdipRect = new Rect()
    567     if (gdipGraphics !is 0 && !gdip) { 
    568         int matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); 
    569         if (matrix is 0) DWT.error(DWT.ERROR_NO_HANDLES); 
     573    Gdip.Rect gdipRect
     574    if (gdipGraphics !is null && !gdip) { 
     575        auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); 
     576        if (matrix is null) DWT.error(DWT.ERROR_NO_HANDLES); 
    570577        Gdip.Graphics_GetTransform(gdipGraphics, matrix); 
    571         int identity = gc.identity(); 
    572         Gdip.Matrix_Invert(identity); 
    573         Gdip.Matrix_Multiply(matrix, identity, Gdip.MatrixOrderAppend); 
    574         Gdip.Matrix_delete(identity); 
     578        auto identity_ = gc.identity(); 
     579        Gdip.Matrix_Invert(identity_); 
     580        Gdip.Matrix_Multiply(matrix, identity_, Gdip.MatrixOrderAppend); 
     581        Gdip.Matrix_delete(identity_); 
    575582        if (!Gdip.Matrix_IsIdentity(matrix)) { 
    576583            lpXform = new float[6]; 
    577             Gdip.Matrix_GetElements(matrix, lpXform); 
     584            Gdip.Matrix_GetElements(matrix, lpXform.ptr); 
    578585        } 
    579586        Gdip.Matrix_delete(matrix); 
     
    583590        } else { 
    584591            Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); 
    585             int rgn = Gdip.Region_new(); 
     592            auto rgn = Gdip.Region_new(); 
    586593            Gdip.Graphics_GetClip(gdipGraphics, rgn); 
    587594            if (!Gdip.Region_IsInfinite(rgn, gdipGraphics)) { 
     
    593600        } 
    594601    } 
    595     int foregroundBrush = 0, state = 0; 
     602    Gdip.Brush* foregroundBrush; 
     603    int state = 0; 
    596604    if (gdip) { 
    597605        gc.checkGC(GC.FOREGROUND); 
     
    604612        if (lpXform !is null) { 
    605613            OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); 
    606             OS.SetWorldTransform(hdc, lpXform); 
    607         } 
    608         if (clipRgn !is 0) { 
     614            OS.SetWorldTransform(hdc, cast(XFORM*)lpXform.ptr); 
     615        } 
     616        if (clipRgn !is null) { 
    609617            OS.SelectClipRgn(hdc, clipRgn); 
    610618            OS.DeleteObject(clipRgn); 
     
    620628        selectionEnd = translateOffset(selectionEnd); 
    621629    } 
    622     RECT rect = new RECT(); 
    623     int selBrush = 0, selPen = 0, selBrushFg = 0; 
     630    RECT rect; 
     631    void* selBrush; 
     632    void* selPen; 
     633    void* selBrushFg; 
     634 
    624635    if (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0) { 
    625636        if (gdip) { 
    626             int bg = selectionBackground.handle; 
    627             int argb = ((alpha & 0xFF) << 24) | ((bg >> 16) & 0xFF) | (bg & 0xFF00) | ((bg & 0xFF) << 16); 
    628             int color = Gdip.Color_new(argb); 
     637            auto bg = selectionBackground.handle; 
     638            auto argb = ((alpha & 0xFF) << 24) | ((bg >> 16) & 0xFF) | (bg & 0xFF00) | ((bg & 0xFF) << 16); 
     639            auto color = Gdip.Color_new(argb); 
    629640            selBrush = Gdip.SolidBrush_new(color); 
    630641            Gdip.Color_delete(color); 
    631             int fg = selectionForeground.handle; 
     642            auto fg = selectionForeground.handle; 
    632643            argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); 
    633644            color = Gdip.Color_new(argb); 
    634645            selBrushFg = Gdip.SolidBrush_new(color); 
    635             selPen = Gdip.Pen_new(selBrushFg, 1); 
     646            selPen = Gdip.Pen_new( cast(Gdip.Brush*)selBrushFg, 1); 
    636647            Gdip.Color_delete(color); 
    637648        } else { 
     
    670681                } 
    671682                if (gdip) { 
    672                     Gdip.Graphics_FillRectangle(gdipGraphics, selBrush, drawX + lineWidth[line], drawY, width, lineHeight - lineSpacing); 
     683                    Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush*)selBrush, drawX + lineWidth[line], drawY, width, lineHeight - lineSpacing); 
    673684                } else { 
    674685                    OS.SelectObject(hdc, selBrush); 
     
    694705                    if (fullSelection) { 
    695706                        if (gdip) { 
    696                             Gdip.Graphics_FillRectangle(gdipGraphics, selBrush, drawX, drawY, run.width, lineHeight - lineSpacing); 
     707                            Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush*)selBrush, drawX, drawY, run.width, lineHeight - lineSpacing); 
    697708                        } else { 
    698709                            OS.SelectObject(hdc, selBrush); 
     
    701712                    } else { 
    702713                        if (run.style !is null && run.style.background !is null) { 
    703                             int bg = run.style.background.handle; 
     714                            auto bg = run.style.background.handle; 
    704715                            int drawRunY = drawY + (baseline - run.ascent); 
    705716                            if (gdip) { 
    706717                                int argb = ((alpha & 0xFF) << 24) | ((bg >> 16) & 0xFF) | (bg & 0xFF00) | ((bg & 0xFF) << 16); 
    707                                 int color = Gdip.Color_new(argb); 
    708                                 int brush = Gdip.SolidBrush_new(color); 
    709                                 Gdip.Graphics_FillRectangle(gdipGraphics, brush, drawX, drawRunY, run.width, run.ascent + run.descent); 
     718                                auto color = Gdip.Color_new(argb); 
     719                                auto brush = Gdip.SolidBrush_new(color); 
     720                                Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush*)brush, drawX, drawRunY, run.width, run.ascent + run.descent); 
    710721                                Gdip.Color_delete(color); 
    711722                                Gdip.SolidBrush_delete(brush); 
    712723                            } else { 
    713                                 int hBrush = OS.CreateSolidBrush (bg); 
    714                                 int oldBrush = OS.SelectObject(hdc, hBrush); 
     724                                auto hBrush = OS.CreateSolidBrush (bg); 
     725                                auto oldBrush = OS.SelectObject(hdc, hBrush); 
    715726                                OS.PatBlt(hdc, drawX, drawRunY, run.width, run.ascent + run.descent, OS.PATCOPY); 
    716727                                OS.SelectObject(hdc, oldBrush); 
     
    724735                            int cChars = run.length; 
    725736                            int gGlyphs = run.glyphCount; 
    726                             int[] piX = new int[1]
    727                             int advances = run.justify !is 0 ? run.justify : run.advances; 
    728                             OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    729                             int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX[0] : piX[0]
     737                            int piX
     738                            int* advances = run.justify !is null ? run.justify : run.advances; 
     739                            OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     740                            int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX
    730741                            rect.left = drawX + runX; 
    731742                            rect.top = drawY; 
    732                             OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    733                             runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX[0] : piX[0]
     743                            OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     744                            runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX
    734745                            rect.right = drawX + runX; 
    735746                            rect.bottom = drawY + lineHeight - lineSpacing; 
    736747                            if (gdip) { 
    737                                 Gdip.Graphics_FillRectangle(gdipGraphics, selBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); 
     748                                Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush*)selBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); 
    738749                            } else { 
    739750                                OS.SelectObject(hdc, selBrush); 
     
    764775                        int cChars = run.length; 
    765776                        int gGlyphs = run.glyphCount; 
    766                         int[] piX = new int[1]
    767                         int advances = run.justify !is 0 ? run.justify : run.advances; 
    768                         OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    769                         int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX[0] : piX[0]
     777                        int piX
     778                        int* advances = run.justify !is null ? run.justify : run.advances; 
     779                        OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     780                        int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX
    770781                        rect.left = drawX + runX; 
    771782                        rect.top = drawY; 
    772                         OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    773                         runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX[0] : piX[0]
     783                        OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     784                        runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX
    774785                        rect.right = drawX + runX; 
    775786                        rect.bottom = drawY + lineHeight; 
     
    777788                    if (gdip) { 
    778789                        OS.BeginPath(hdc); 
    779                         OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, 0, null, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
     790                        OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, 0, null, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
    780791                        OS.EndPath(hdc); 
    781792                        int count = OS.GetPath(hdc, null, null, 0); 
    782793                        int[] points = new int[count*2]; 
    783                         byte[] types = new byte[count]; 
    784                         OS.GetPath(hdc, points, types, count); 
     794                        ubyte[] types = new ubyte[count]; 
     795                        OS.GetPath(hdc, cast(POINT*)points.ptr, types.ptr, count); 
    785796                        for (int typeIndex = 0; typeIndex < types.length; typeIndex++) { 
    786797                            int newType = 0; 
     
    794805                            types[typeIndex] = cast(byte)newType; 
    795806                        } 
    796                         int path = Gdip.GraphicsPath_new(points, types, count, Gdip.FillModeAlternate); 
    797                         if (path is 0) DWT.error(DWT.ERROR_NO_HANDLES); 
    798                         int brush = foregroundBrush; 
     807                        auto path = Gdip.GraphicsPath_new(cast(Gdip.Point*)points.ptr, cast(byte*)types.ptr, count, Gdip.FillModeAlternate); 
     808                        if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 
     809                        auto brush = foregroundBrush; 
    799810                        if (fullSelection) { 
    800                             brush = selBrushFg; 
     811                            brush = cast(Gdip.Brush*)selBrushFg; 
    801812                        } else { 
    802813                            if (run.style !is null && run.style.foreground !is null) { 
    803                                 int fg = run.style.foreground.handle; 
     814                                auto fg = run.style.foreground.handle; 
    804815                                int argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); 
    805                                 int color = Gdip.Color_new(argb); 
    806                                 brush = Gdip.SolidBrush_new(color); 
     816                                auto color = Gdip.Color_new(argb); 
     817                                brush = cast(Gdip.Brush*)Gdip.SolidBrush_new(color); 
    807818                                Gdip.Color_delete(color); 
    808819                            } 
     
    815826                            gdipRect.Height = rect.bottom - rect.top; 
    816827                            gstate = Gdip.Graphics_Save(gdipGraphics); 
    817                             Gdip.Graphics_SetClip(gdipGraphics, gdipRect, Gdip.CombineModeExclude); 
     828                            Gdip.Graphics_SetClip(gdipGraphics, &gdipRect, Gdip.CombineModeExclude); 
    818829                        } 
    819830                        int antialias = Gdip.Graphics_GetSmoothingMode(gdipGraphics), textAntialias = 0; 
     
    840851                        Gdip.Graphics_SetSmoothingMode(gdipGraphics, antialias); 
    841852                        if (run.style !is null && (run.style.underline || run.style.strikeout)) { 
    842                             int newPen = hasSelection ? selPen : Gdip.Pen_new(brush, 1); 
     853                            auto newPen = hasSelection ? cast(Gdip.Pen*)selPen : Gdip.Pen_new(brush, 1); 
    843854                            Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); 
    844855                            if (run.style.underline) { 
     
    856867                            Gdip.Graphics_Restore(gdipGraphics, gstate); 
    857868                            gstate = Gdip.Graphics_Save(gdipGraphics); 
    858                             Gdip.Graphics_SetClip(gdipGraphics, gdipRect, Gdip.CombineModeIntersect); 
     869                            Gdip.Graphics_SetClip(gdipGraphics, &gdipRect, Gdip.CombineModeIntersect); 
    859870                            Gdip.Graphics_SetSmoothingMode(gdipGraphics, textAntialias); 
    860                             Gdip.Graphics_FillPath(gdipGraphics, selBrushFg, path); 
     871                            Gdip.Graphics_FillPath(gdipGraphics, cast(Gdip.Brush*)selBrushFg, path); 
    861872                            Gdip.Graphics_SetSmoothingMode(gdipGraphics, antialias); 
    862873                            if (run.style !is null && (run.style.underline || run.style.strikeout)) { 
     
    864875                                if (run.style.underline) { 
    865876                                    int underlineY = drawY + baseline + 1 - run.style.rise; 
    866                                     Gdip.Graphics_DrawLine(gdipGraphics, selPen, rect.left, underlineY, rect.right, underlineY); 
     877                                    Gdip.Graphics_DrawLine(gdipGraphics, cast(Gdip.Pen*)selPen, rect.left, underlineY, rect.right, underlineY); 
    867878                                } 
    868879                                if (run.style.strikeout) { 
    869880                                    int strikeoutY = drawRunY + run.leading + (run.ascent - run.style.rise) / 2; 
    870                                     Gdip.Graphics_DrawLine(gdipGraphics, selPen, rect.left, strikeoutY, rect.right, strikeoutY); 
     881                                    Gdip.Graphics_DrawLine(gdipGraphics, cast(Gdip.Pen*)selPen, rect.left, strikeoutY, rect.right, strikeoutY); 
    871882                                } 
    872883                                Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); 
     
    875886                        } 
    876887                        Gdip.GraphicsPath_delete(path); 
    877                         if (brush !is selBrushFg && brush !is foregroundBrush) Gdip.SolidBrush_delete(brush); 
     888                        if (brush !is selBrushFg && brush !is foregroundBrush) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush*)brush); 
    878889                    }  else { 
    879890                        int fg = foreground; 
     
    884895                        } 
    885896                        OS.SetTextColor(hdc, fg); 
    886                         OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, 0, null, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
     897                        OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, 0, null, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
    887898                        if (run.style !is null && (run.style.underline || run.style.strikeout)) { 
    888                             int newPen = hasSelection && fg is selectionForeground.handle ? selPen : OS.CreatePen(OS.PS_SOLID, 1, fg); 
    889                             int oldPen = OS.SelectObject(hdc, newPen); 
     899                            auto newPen = hasSelection && fg is selectionForeground.handle ? cast(HPEN)selPen : OS.CreatePen(OS.PS_SOLID, 1, fg); 
     900                            auto oldPen = OS.SelectObject(hdc, newPen); 
    890901                            if (run.style.underline) { 
    891902                                int underlineY = drawY + baseline + 1 - run.style.rise; 
    892                                 OS.MoveToEx(hdc, drawX, underlineY, 0); 
     903                                OS.MoveToEx(hdc, drawX, underlineY, null); 
    893904                                OS.LineTo(hdc, drawX + run.width, underlineY); 
    894905                            } 
    895906                            if (run.style.strikeout) { 
    896907                                int strikeoutY = drawRunY + run.leading + (run.ascent - run.style.rise) / 2; 
    897                                 OS.MoveToEx(hdc, drawX, strikeoutY, 0); 
     908                                OS.MoveToEx(hdc, drawX, strikeoutY, null); 
    898909                                OS.LineTo(hdc, drawX + run.width, strikeoutY); 
    899910                            } 
     
    903914                        if (partialSelection && fg !is selectionForeground.handle) { 
    904915                            OS.SetTextColor(hdc, selectionForeground.handle); 
    905                             OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
     916                            OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, OS.ETO_CLIPPED, &rect, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); 
    906917                            if (run.style !is null && (run.style.underline || run.style.strikeout)) { 
    907                                 int oldPen = OS.SelectObject(hdc, selPen); 
     918                                auto oldPen = OS.SelectObject(hdc, selPen); 
    908919                                if (run.style.underline) { 
    909920                                    int underlineY = drawY + baseline + 1 - run.style.rise; 
    910                                     OS.MoveToEx(hdc, rect.left, underlineY, 0); 
     921                                    OS.MoveToEx(hdc, rect.left, underlineY, null); 
    911922                                    OS.LineTo(hdc, rect.right, underlineY); 
    912923                                } 
    913924                                if (run.style.strikeout) { 
    914925                                    int strikeoutY = drawRunY + run.leading + (run.ascent - run.style.rise) / 2; 
    915                                     OS.MoveToEx(hdc, rect.left, strikeoutY, 0); 
     926                                    OS.MoveToEx(hdc, rect.left, strikeoutY, null); 
    916927                                    OS.LineTo(hdc, rect.right, strikeoutY); 
    917928                                } 
     
    926937    } 
    927938    if (gdip) { 
    928         if (selBrush !is 0) Gdip.SolidBrush_delete(selBrush); 
    929         if (selBrushFg !is 0) Gdip.SolidBrush_delete(selBrushFg); 
    930         if (selPen !is 0) Gdip.Pen_delete(selPen); 
     939        if (selBrush !is null) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush*)selBrush); 
     940        if (selBrushFg !is null) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush*)selBrushFg); 
     941        if (selPen !is null) Gdip.Pen_delete(cast(Gdip.Pen*)selPen); 
    931942    } else { 
    932943        OS.RestoreDC(hdc, state); 
    933         if (gdipGraphics !is 0) Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); 
    934         if (selBrush !is 0) OS.DeleteObject (selBrush); 
    935         if (selPen !is 0) OS.DeleteObject (selPen); 
     944        if (gdipGraphics !is null) Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); 
     945        if (selBrush !is null) OS.DeleteObject (selBrush); 
     946        if (selPen !is null) OS.DeleteObject (selPen); 
    936947    } 
    937948} 
     
    10231034    checkLayout(); 
    10241035    computeRuns(null); 
    1025     int length = text.length()
     1036    int length = text.length
    10261037    if (length is 0) return new Rectangle(0, 0, 0, 0); 
    10271038    if (start > end) return new Rectangle(0, 0, 0, 0); 
     
    10461057                cx = metrics.width * (start - run.start); 
    10471058            } else if (!run.tab) { 
    1048                 int[] piX = new int[1]
    1049                 int advances = run.justify !is 0 ? run.justify : run.advances; 
    1050                 OS.ScriptCPtoX(start - run.start, false, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    1051                 cx = isRTL ? run.width - piX[0] : piX[0]
     1059                int piX
     1060                int* advances = run.justify !is null ? run.justify : run.advances; 
     1061                OS.ScriptCPtoX(start - run.start, false, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     1062                cx = isRTL ? run.width - piX : piX
    10521063            } 
    10531064            if (run.analysis.fRTL ^ isRTL) { 
     
    10631074                cx = metrics.width * (end - run.start + 1); 
    10641075            } else if (!run.tab) { 
    1065                 int[] piX = new int[1]
    1066                 int advances = run.justify !is 0 ? run.justify : run.advances; 
    1067                 OS.ScriptCPtoX(end - run.start, true, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX); 
    1068                 cx = isRTL ? run.width - piX[0] : piX[0]
     1076                int piX
     1077                int* advances = run.justify !is null ? run.justify : run.advances; 
     1078                OS.ScriptCPtoX(end - run.start, true, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
     1079                cx = isRTL ? run.width - piX : piX
    10691080            } 
    10701081            if (run.analysis.fRTL ^ isRTL) { 
     
    11521163} 
    11531164 
    1154 int getItemFont (StyleItem item) { 
    1155     if (item.fallbackFont !is 0) return item.fallbackFont; 
     1165HFONT getItemFont (StyleItem item) { 
     1166    if (item.fallbackFont !is null) return cast(HFONT) item.fallbackFont; 
    11561167    if (item.style !is null && item.style.font !is null) { 
    11571168        return item.style.font.handle; 
     
    11801191    checkLayout(); 
    11811192    computeRuns(null); 
    1182     int length = text.length()
     1193    int length = text.length
    11831194    if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    11841195    offset = translateOffset(offset); 
     
    12781289    checkLayout(); 
    12791290    computeRuns(null); 
    1280     int length = text.length()
     1291    int length = text.length
    12811292    if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    12821293    offset = translateOffset(offset); 
     
    13061317    computeRuns(null); 
    13071318    if (!(0 <= lineIndex && lineIndex < runs.length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    1308     int hDC = device.internal_new_GC(null); 
    1309     int srcHdc = OS.CreateCompatibleDC(hDC); 
     1319    auto hDC = device.internal_new_GC(null); 
     1320    auto srcHdc = OS.CreateCompatibleDC(hDC); 
    13101321    TEXTMETRIC lptm; 
    13111322    OS.SelectObject(srcHdc, font !is null ? font.handle : device.systemFont); 
     
    13171328    int descent = Math.max(lptm.tmDescent, this.descent); 
    13181329    int leading = lptm.tmInternalLeading; 
    1319     if (text.length() !is 0) { 
     1330    if (text.length !is 0) { 
    13201331        StyleItem[] lineRuns = runs[lineIndex]; 
    13211332        for (int i = 0; i<lineRuns.length; i++) { 
     
    13331344    lptm.tmInternalLeading = leading; 
    13341345    lptm.tmAveCharWidth = 0; 
    1335     return FontMetrics.win32_new(lptm); 
     1346    return FontMetrics.win32_new(&lptm); 
    13361347} 
    13371348 
     
    13761387    checkLayout(); 
    13771388    computeRuns(null); 
    1378     int length = text.length()
     1389    int length = text.length
    13791390    if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    1380     length = segmentsText.length()
     1391    length = segmentsText.length
    13811392    offset = translateOffset(offset); 
    13821393    int line; 
     
    14061417                    int cChars = run.length; 
    14071418                    int gGlyphs = run.glyphCount; 
    1408                     int[] piX = new int[1]
    1409                     int advances = run.justify !is 0 ? run.justify : run.advances; 
    1410                     OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX); 
     1419                    int piX
     1420                    int* advances = run.justify !is null ? run.justify : run.advances; 
     1421                    OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); 
    14111422                    if ((orientation & DWT.RIGHT_TO_LEFT) !is 0) { 
    1412                         result = new Point(width + (run.width - piX[0]), lineY[line]); 
     1423                        result = new Point(width + (run.width - piX), lineY[line]); 
    14131424                    } else { 
    1414                         result = new Point(width + piX[0], lineY[line]); 
     1425                        result = new Point(width + piX, lineY[line]); 
    14151426                    } 
    14161427                } 
     
    14511462int _getOffset(int offset, int movement, bool forward) { 
    14521463    computeRuns(null); 
    1453     int length = text.length()
     1464    int length = text.length
    14541465    if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    14551466    if (forward && offset is length) return length; 
     
    14571468    int step = forward ? 1 : -1; 
    14581469    if ((movement & DWT.MOVEMENT_CHAR) !is 0) return offset + step; 
    1459     length = segmentsText.length()
     1470    length = segmentsText.length
    14601471    offset = translateOffset(offset); 
    1461     SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR()
    1462     SCRIPT_PROPERTIES properties = new  SCRIPT_PROPERTIES()
     1472    SCRIPT_LOGATTR* logAttr
     1473    SCRIPT_PROPERTIES* properties
    14631474    int i = forward ? 0 : allRuns.length - 1; 
    14641475    offset = validadeOffset(offset, step); 
     
    14681479            if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); 
    14691480            if (run.tab) return untranslateOffset(run.start); 
    1470             OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof)
     1481            properties = device.scripts[run.analysis.eScript]
    14711482            bool isComplex = properties.fNeedsCaretInfo || properties.fNeedsWordBreaking; 
    14721483            if (isComplex) breakRun(run); 
    14731484            while (run.start <= offset && offset < run.start + run.length) { 
    14741485                if (isComplex) { 
    1475                     OS.MoveMemory(logAttr, run.psla + ((offset - run.start) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); 
     1486                    logAttr = run.psla + (offset - run.start); 
    14761487                } 
    14771488                switch (movement) { 
     
    15171528        i += step; 
    15181529    } while (0 <= i && i < allRuns.length - 1 && 0 <= offset && offset < length); 
    1519     return forward ? text.length() : 0; 
     1530    return forward ? text.length : 0; 
    15201531} 
    15211532 
     
    16071618            int cChars = run.length; 
    16081619            int cGlyphs = run.glyphCount; 
    1609             int[] piCP = new int[1]
    1610             int[] piTrailing = new int[1]
     1620            int piCP
     1621            int piTrailing
    16111622            if ((orientation & DWT.RIGHT_TO_LEFT) !is 0) { 
    16121623                xRun = run.width - xRun; 
    16131624            } 
    1614             int advances = run.justify !is 0 ? run.justify : run.advances; 
    1615             OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piCP, piTrailing); 
    1616             if (trailing !is null) trailing[0] = piTrailing[0]
    1617             return untranslateOffset(run.start + piCP[0]); 
     1625            int* advances = run.justify !is null ? run.justify : run.advances; 
     1626            OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piCP, &piTrailing); 
     1627            if (trailing !is null) trailing[0] = piTrailing
     1628            return untranslateOffset(run.start + piCP); 
    16181629        } 
    16191630        width += run.width; 
     
    17111722    int nSegments = segments.length; 
    17121723    if (nSegments <= 1) return text; 
    1713     int length = text.length()
     1724    int length = text.length
    17141725    if (length is 0) return text; 
    17151726    if (nSegments is 2) { 
     
    17201731    char[] newChars = new char[length + nSegments]; 
    17211732    int charCount = 0, segmentCount = 0; 
    1722     char separator = orientation is DWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK; 
     1733    wchar separator = orientation is DWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK; 
    17231734    while (charCount < length) { 
    17241735        if (segmentCount < nSegments && charCount is segments[segmentCount]) { 
     
    17321743        newChars[charCount + segmentCount++] = separator; 
    17331744    } 
    1734     return new char[](newChars, 0, Math.min(charCount + segmentCount, newChars.length))
     1745    return newChars[ 0 .. Math.min(charCount + segmentCount, newChars.length)].dup
    17351746} 
    17361747 
     
    17641775public TextStyle getStyle (int offset) { 
    17651776    checkLayout(); 
    1766     int length = text.length()
     1777    int length = text.length
    17671778    if (!(0 <= offset && offset < length)) DWT.error(DWT.ERROR_INVALID_RANGE); 
    17681779    for (int i=1; i<styles.length; i++) { 
    &helli