import os
import sys
import io
import tempfile
import shutil
import re

usage = """
PDF Toolbox 3-Heights(R) -> 4-Heights(R) Source Code Migration Tool
Version 1.0 © 2021 PDF Tools AG
Minimum supported Python Version: 3.4

Usage:
  python 3hto4h.py [options] <directory>

Options:
  -m       Don't produce TODO markers in the source files

Description:
  Traverses the given <directory> recursively and converts Java, C#,
  and C source code files by in-place substitution.
  Files in <directory> and in sub-directories are overwritten.
"""

# Global options
mark = True


def main():
    # Check python version
    if sys.version_info[0] < 3 or sys.version_info[1] < 4:
        print(usage)
        sys.exit()

    # Check arguments
    global mark
    if len(sys.argv) < 2 or len(sys.argv) > 3:
        print(usage)
        sys.exit()
    if sys.argv[1] == '-m':
        mark = False
    inDir = sys.argv[len(sys.argv) - 1]
    if not os.path.isdir(inDir):
        print(usage)
        sys.exit()

    # Process
    print(f'- Finding source files in "{inDir}"')
    files = traverseDir(inDir)

    print('- Compiling regular expressions')
    for t in files.keys():
        if len(files[t]) > 0:
            compileRegEx(t)

    print('- Processing files')
    with tempfile.TemporaryDirectory() as tempDir:
        for t in files.keys():
            for f in files[t]:
                process(t, f, tempDir)


def checkFileExt(fileName, ext):
    for e in ext:
        if fileName.endswith('.' + e):
            return True
    return False


def traverseDir(inDir):
    files = {t: [] for t in data.keys()}
    for root, dirs, names in os.walk(inDir):
        for t in data.keys():
            files[t] += [os.path.join(root, f) for f in names
                         if checkFileExt(f, data[t]['ext'])]
    return files


def compileRegEx(t):
    d = data[t]
    d['sub-cmp'] = [re.compile(s[0]) for s in d['sub']]
    global mark
    if mark:
        d['mark-cmp'] = [re.compile(s[0]) for s in d['mark']]


def process(t, inPath, tempDir):
    s = data[t]['sub']
    sc = data[t]['sub-cmp']
    m = []
    mc = []
    global mark
    if mark:
        m = data[t]['mark']
        mc = data[t]['mark-cmp']
    outPath = os.path.join(tempDir, os.path.basename(inPath))
    with io.open(outPath, 'w+', encoding='utf8') as outFile:
        with io.open(inPath, 'r', encoding='utf8') as inFile:
            for line in inFile:
                for i in range(len(sc)):
                    line = sc[i].sub(s[i][1], line)
                for i in range(len(mc)):
                    line = mc[i].sub(m[i][1], line, 1)
                outFile.write(line)
    shutil.move(outPath, inPath)


data = {
    'c':
    {
        'ext': ('c', 'cpp', 'cxx', 'h', 'hpp', 'hxx',),
        'sub':
        (
            ### Include ############################
            (r'#include "pdftoolboxapi_c.h"', r'#include "PdfToolbox.h"'),

            ### Ptx ################################
            # Types
            (r'\bTPdfErrorCode\b', r'TPtx_ErrorCode'), # enum values missing
            (r'\bePdfSuccess\b', r'ePtx_Error_Success'),
            (r'\bePdfError(Conformance|Corrupt|Exists|Generic|IO|IllegalArgument|IllegalState|License|NotFound|Password|UnknownFormat|UnsupportedFeature|UnsupportedOperation)\b', r'ePtx_Error_\1'),
            (r'\bTPdfStringMap\b', r'TPtx_StringMap'),

            # Functions
            (r'\bPdf(Equals|GetHashCode|GetLastError|GetLastErrorMessage|Initialize|Release|Uninitialize)\b', r'Ptx_\1'),
            (r'\bPdfSetLicenseKey\b', r'Ptx_Sdk_Initialize'),
            (r'\bPdfGetProductVersion\b', r'Ptx_Sdk_GetVersion'),
            (r'\bPdfStringMap(\w*)\b', r'Ptx_StringMap_\1'),

            ### PtxGeom ############################
            # Types
            (r'\bTPdfRotation\b', r'TPtxGeom_Rotation'),
            (r'\bePdfRotateNoRotation\b', r'ePtxGeom_Rotation_None'),
            (r'\bePdfRotate(\w+)\b', r'ePtxGeom_Rotation_\1'),
            (r'\bTPdfTextAlignment\b', r'TPtxGeom_HorizontalAlignment'),
            (r'\bePdfTextAlignment(\w+)\b', r'ePtxGeom_HorizontalAlignment_\1'),

            ### PtxGeomReal ########################
            # Types
            (r'\bTPdfTransformation\b', r'TPtxGeomReal_AffineTransform'),
            (r'\bTPdf(Point|Rectangle|Size)\b', r'TPtxGeomReal_\1'),

            # Functions
            (r'\bPdfTransformationRotate\(([^)]*)', r'PtxGeomReal_AffineTransform_Rotate(\1, NULL'),
            (r'\bPdfTransformationRotateAround\b', r'PtxGeomReal_AffineTransform_Rotate'),
            (r'\bPdfTransformation(\w+)\b', r'PtxGeomReal_AffineTransform_\1'),

            ### PtxPdf #############################
            # Types
            (r'\bTPDFCompliance\b', r'TPtxPdf_Conformance'),
            (r'\bTPdfConformance\b', r'TPtxPdf_Conformance'),
            (r'\beP[Dd][Ff](10|11|12|13|14|15|16|17|20)\b', r'ePtxPdf_Conformance_Pdf\1'),
            (r'\beP[Dd][Ff]A1b\b', r'ePtxPdf_Conformance_PdfA1B'),
            (r'\beP[Dd][Ff]A1a\b', r'ePtxPdf_Conformance_PdfA1A'),
            (r'\beP[Dd][Ff]A2b\b', r'ePtxPdf_Conformance_PdfA2B'),
            (r'\beP[Dd][Ff]A2u\b', r'ePtxPdf_Conformance_PdfA2U'),
            (r'\beP[Dd][Ff]A2a\b', r'ePtxPdf_Conformance_PdfA2A'),
            (r'\beP[Dd][Ff]A3b\b', r'ePtxPdf_Conformance_PdfA3B'),
            (r'\beP[Dd][Ff]A3u\b', r'ePtxPdf_Conformance_PdfA3U'),
            (r'\beP[Dd][Ff]A3a\b', r'ePtxPdf_Conformance_PdfA3A'),
            (r'\bTP[Dd][Ff]Permission\b', r'TPtxPdf_Permission'),
            (r'\bePerm(Annotate|Assemble|Copy|DigitalPrint|FillForms|Modify|Print|SupportDisabilities)\b', r'ePtxPdf_Permission_\1'),
            (r'\bTPdf(Document|FileReference|FileReferenceList|Metadata|Page|PageList)\b', r'TPtxPdf_\1'),

            # Functions
            (r'\bPdfDocumentCreate(FileReference|Metadata|Page)\b', r'PtxPdf_\1_Create'),
            (r'\bPdfDocumentCreateCircleAnnotation\b', r'PtxPdfAnnots_EllipseAnnotation_Create'),
            (r'\bPdfDocumentCreate(CustomStamp|FileAttachment|FreeText|StickyNote|TextStamp)Annotation\b', r'PtxPdfAnnots_\1_Create'),
            (r'\bPdfDocumentCreateFreeDrawingAnnotation\b', r'PtxPdfAnnots_InkAnnotation_Create'),
            (r'\bPdfDocumentCreate(LineAnnotation|PolyLineAnnotation|PolygonAnnotation)\b', r'PtxPdfAnnots_\1_Create'),
            (r'\bPdfDocumentCreateSquareAnnotation\b', r'PtxPdfAnnots_RectangleAnnotation_Create'),
            (r'\bPdfDocumentCreate(Alpha|Blending|Solid)Paint\b', r'PtxPdfContent_Paint_Create'),
            (r'\bPdfDocumentCreate(Font|Group|Image|ImageMask|Text)\b', r'PtxPdfContent_\1_Create'),
            (r'\bPdfDocumentCreateDeviceColorSpace\b', r'PtxPdfContent_ColorSpace_CreateProcessColorSpace'),
            (r'\bPdfDocumentCreateICCColorSpace\b', r'PtxPdfContent_IccBasedColorSpace_Create'),
            (r'\bPdfDocumentCreateSystemFont\b', r'PtxPdfContent_Font_CreateFromSystem'),
            (r'\bPdfDocumentCreate(CheckBox|ComboBox|ListBox)Field\b', r'PtxPdfForms_\1_Create'),
            (r'\bPdfDocumentCreate(CombTextField|GeneralTextField|SubForm)\b', r'PtxPdfForms_\1_Create'),
            (r'\bPdfDocumentCreateRadioButtonField\b', r'PtxPdfForms_RadioButtonGroup_Create'),
            (r'\bPdfDocumentCreateNamed(Destination|OutlineItem)\b', r'PtxPdfNav__Create'),
            (r'\bPdfDocumentCopy(FileReference|Metadata|Page)\b', r'PtxPdf_\1_Copy'),
            (r'\bPdfDocumentCopyPageAsGroup\b', r'PtxPdfContent_Group_CopyFromPage'),
            (r'\bPdfDocumentCopyAnnotation\b', r'PtxPdfAnnots_Annotation_Copy'),
            (r'\bPdfDocumentCopy(ColorSpace|ContentElement)\b', r'PtxPdfContent_\1_Copy'),
            (r'\bPdfDocumentCopyGroupElementWithoutContent\b', r'PtxPdfContent_Group_CopyWithoutContent'),
            (r'\bPdfDocumentCopyFormFieldNode\b', r'PtxPdfForms_FieldNode_Copy'),
            (r'\bPdfDocumentCopy(OutlineItem|ViewerSettings)\b', r'PtxPdfNav_\1_Copy'),
            (r'\bPdfDocument([GS])et(Conformance|Metadata|Pages|OutputIntent|FormFields|SignatureFields|AssociatedFiles|OpenDestination|Permissions|ViewerSettings)\b', r'PtxPdf_Document_\1et\2'),
            (r'\bPdfDocumentGetEmbeddedFiles\b', r'PtxPdf_Document_GetPlainEmbeddedFiles'),
            (r'\bPdfDocumentGetOutlineItems\b', r'PtxPdf_Document_GetOutline'),

            (r'\bPdf(FileReference|Page)ListAppend\b', r'PtxPdf_\1List_Add'),

            (r'\bPdf(Document|FileReferenceList|FileReference|Metadata|PageList|Page)(\w+)\b', r'PtxPdf_\1_\2'),
            (r'\bPtxPdf_Document_SetOutputIntent\((\s*\w+,\s*)PtxPdfContent_ColorSpace_Copy\(', r'PtxPdf_Document_SetOutputIntent(\1PtxPdfContent_IccBasedColorSpace_Copy('),

            ### PtxPdfAnnots #######################
            # Types
            (r'\bTPdfAnnotationLineEnding\b', r'TPtxPdfAnnots_LineEnding'),
            (r'\bePdfAnnotationLineEndingReversed(Closed|Open)Arrow\b', r'ePtxPdfAnnots_LineEnding_\1ArrowTail'),
            (r'\bePdfAnnotationLineEnding(\w+)\b', r'ePtxPdfAnnots_LineEnding_\1'),
            (r'\bTPdfAnnotationPopup\b', r'TPtxPdfAnnots_Popup'),
            (r'\bePdfAnnotationTypeCircleAnnotation\b', r'ePtxPdfAnnots_AnnotationType_Ellipse'),
            (r'\bePdfAnnotationTypeFreeDrawingAnnotation\b', r'ePtxPdfAnnots_AnnotationType_InkAnnotation'),
            (r'\bePdfAnnotationTypeSquareAnnotation\b', r'ePtxPdfAnnots_AnnotationType_RectangleAnnotation'),
            (r'\bePdfAnnotationType(CustomStamp|FileAttachment|FreeText|Highlight|Squiggly|Stamp|StickyNote|StrikeThrough|TextInsert|TextMarkup|TextStamp|Underline)Annotation\b', r'ePtxPdfAnnots_AnnotationType_\1'),
            (r'\bePdfAnnotationType(Annotation|DrawingAnnotation|LineAnnotation|MarkupAnnotation|PolyLineAnnotation|PolygonAnnotation)\b', r'ePtxPdfAnnots_AnnotationType_\1'),
            (r'\bTPdfCircleAnnotation\b', r'TPtxPdfAnnots_EllipseAnnotation'),
            (r'\bePdfDrawingAnnotationTypeCircleAnnotation\b', r'ePtxPdfAnnots_DrawingAnnotationType_Ellipse'),
            (r'\bePdfDrawingAnnotationTypeFreeDrawingAnnotation\b', r'ePtxPdfAnnots_DrawingAnnotationType_InkAnnotation'),
            (r'\bePdfDrawingAnnotationTypeSquareAnnotation\b', r'ePtxPdfAnnots_DrawingAnnotationType_RectangleAnnotation'),
            (r'\bePdfDrawingAnnotationType(Drawing|Line|PolyLine|Polygon)Annotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_\1Annotation'),
            (r'\bTPdfFreeDrawingAnnotation\b', r'TPtxPdfAnnots_InkAnnotation'),
            (r'\bePdfMarkupAnnotationTypeCircleAnnotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_Ellipse'),
            (r'\bePdfMarkupAnnotationTypeFreeDrawingAnnotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_InkAnnotation'),
            (r'\bePdfMarkupAnnotationTypeSquareAnnotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_RectangleAnnotation'),
            (r'\bePdfMarkupAnnotationType(CustomStamp|FileAttachment|FreeText|Highlight|Squiggly|Stamp|StickyNote|StrikeThrough|TextInsert|TextMarkup|TextStamp|Underline)Annotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_\1'),
            (r'\bePdfMarkupAnnotationType(Drawing|Line|Markup|PolyLine|Polygon)Annotation\b', r'ePtxPdfAnnots_MarkupAnnotationType_\1Annotation'),
            (r'\bTPdf(Stamp|TextMarkup)AnnotationType\b', r'TPtxPdfAnnots_\1Type'),
            (r'\bePdfStampAnnotationType(CustomStamp|Stamp|TextStamp)Annotation\b', r'ePtxPdfAnnots_StampType_\1'),
            (r'\bTPdfSquareAnnotation\b', r'TPtxPdfAnnots_RectangleAnnotation'),
            (r'\bePdfTextMarkupAnnotationType(Highlight|Squiggly|StrikeThrough|TextInsert|TextMarkup|Underline)Annotation\b', r'ePtxPdfAnnots_TextMarkupType_\1'),
            (r'\bePdfTextStampType(\w+)\b', r'ePtxPdfAnnots_TextStampType_\1'),
            (r'\bTPdf(CustomStamp|FileAttachment|FileAttachmentIcon|FreeText|Highlight|Squiggly|Stamp|StickyNote|StrikeThrough|TextInsert|TextMarkup|TextStamp|Underline)Annotation\b', r'TPtxPdfAnnots_\1'),
            (r'\bePdf(FileAttachmentIcon)(\w+)\b', r'ePtxPdfAnnots_\1_\2'),
            (r'\bTPdf(Annotation|AnnotationList|AnnotationType|DrawingAnnotation|LineAnnotation|MarkupAnnotation|MarkupAnnotationType|MarkupInfo|MarkupInfoList|PolyLineAnnotation|PolygonAnnotation|TextStampType)\b', r'TPtxPdfAnnots_\1'),

            # Functions
            (r'\bPdfAnnotationGetRectangle\b', r'PtxPdfAnnots_Annotation_GetBoundingBox'),
            (r'\bPdfAnnotationListAppend\b', r'PtxPdfAnnots_AnnotationList_Add'),
            (r'\bPdfAnnotationPopup(\w+)\b', r'PtxPdfAnnots_Popup_\1'),

            (r'\bPdf(CustomStamp|FileAttachment|FreeText|Stamp|StickyNote|TextInsert|TextMarkup|TextStamp)Annotation(\w+)\b', r'PtxPdfAnnots_\1_\2'),
            (r'\bPdf(AnnotationList|Annotation|DrawingAnnotation|LineAnnotation|MarkupAnnotation|MarkupInfoList|MarkupInfo|PolyLineAnnotation|PolygonAnnotation)(\w+)\b', r'PtxPdfAnnots_\1_\2'),

            ### PtxPdfContent ######################
            # Types
            (r'\bePdfBlendMode(w+)\b', r'ePtxPdfContent_BlendMode_\1'),
            (r'\bePdfRule(w+)\b', r'ePtxPdfContent_InsideRule_\1 '),
            (r'\bePdfColorSpaceDeviceRGB\b', r'ePtxPdfContent_ColorSpaceType_DeviceRgbColorSpace'),
            (r'\bePdfColorSpaceDeviceCMYK\b', r'ePtxPdfContent_ColorSpaceType_DeviceCmykColorSpace'),
            (r'\bePdfColorSpaceCalGray\b', r'ePtxPdfContent_ColorSpaceType_CalibratedGrayColorSpace'),
            (r'\bePdfColorSpaceCalRGB\b', r'ePtxPdfContent_ColorSpaceType_CalibratedRgbColorSpace'),
            (r'\bePdfColorSpaceICCBased\b', r'ePtxPdfContent_ColorSpaceType_IccBasedColorSpace'),
            (r'\bePdfColorSpace(w+)\b', r'ePtxPdfContent_ColorSpaceType_\1ColorSpace'),
            (r'\bePdfContentElementType(\w+)\b', r'ePtxPdfContent_ContentElementType_\1'),
            (r'\bTPdfDeviceColorSpaceType\b', r'TPtxPdfContent_ProcessColorSpaceType'),
            (r'\bePdfDeviceColorSpaceTypeCMYK\b', r'ePtxPdfContent_ProcessColorSpaceType_Cmyk'),
            (r'\bePdfDeviceColorSpaceTypeRGB\b', r'ePtxPdfContent_ProcessColorSpaceType_Rgb'),
            (r'\bePdfDeviceColorSpaceType(w+)\b', r'ePtxPdfContent_ProcessColorSpaceType_\1'),
            (r'\bePdf(LineCap|LineJoin)(w+)\b', r'ePtxPdfContent_\1Style_\1'),
            (r'\bTPdfUngroupingSet\b', r'TPtxPdfContent_UngroupingSelection'),
            (r'\bePdfUngroupingSet(\w+)\b', r'ePtxPdfContent_UngroupingSelection_\1'),
            (r'\bTPdf(BlendMode|ColorSpace|ColorSpaceType|Content|ContentElement|ContentElementType|ContentExtractor|ContentExtractorIterator|ContentGenerator|Font|Group|GroupElement|Image|ImageElement|ImageMask|ImageMaskElement|InsideRule|LineCapStyle|LineJoinStyle|Paint|Path|PathElement|PathGenerator|ShadingElement|Text|TextElement|TextFragment|TextGenerator)\b', r'TPtxPdfContent_\1'),

            # Functions
            (r'\bPdfColorSpaceGetComponents\b', r'PtxPdfContent_ColorSpace_GetComponentCount'),
            (r'\bPdfColorSpaceGetType\b', r'PtxPdfContent_ColorSpace_GetType'),
            (r'\bPdfContentElement(GetBoundingBox|SetTransform|GetType)\b', r'PtxPdfContent_ContentElement_\1'),
            (r'\bPdfContentGenerator(Save|Restore|Transform)\b', r'PtxPdfContent_ContentGenerator_\1'),
            (r'\bPdfContentGeneratorPaint(Image|ImageMask|Path|Text|Group)\b', r'PtxPdfContent_ContentGenerator_Paint\1'),
            (r'\bPdfFontGetCharWidth\b', r'PtxPdfContent_Font_GetCharacterWidth'),
            (r'\bPdfImageGet(BitsPerComponent|ColorSpace)\b', r'PtxPdfContent_Image_Get\1'),
            (r'\bPdfPaintGet(ColorSpace|Color)\b', r'PtxPdfContent_Paint_Get\1'),
            (r'\bPdfPathElementGet(AlignmentBox|Path)\b', r'PtxPdfContent_PathElement_Get\1'),
            (r'\bPdfTextFragmentGet(BoundingBox|Transform|UnicodeString)\b', r'PtxPdfContent_TextFragment_Get\1'),
            (r'\bPdfTextGenerator(GetWidth|Show|ShowLine|MoveTo)\b', r'PtxPdfContent_TextGenerator_\1'),
            (r'\bPdfTextGeneratorSetCharSpacing\b', r'PtxPdfContent_TextGenerator_SetCharacterSpacing'),
            (r'\bPdfTextGeneratorSet(Font|FontSize|WordSpacing|HorizontalScaling|Leading|Rise)\b', r'PtxPdfContent_TextGenerator_Set\1'),

            (r'\bPdfNew(ContentGenerator|PathGenerator|Path|TextGenerator|ContentExtractor)\b', r'PtxPdfContent_\1_New'),
            (r'\bPdf(ContentExtractorIterator|ContentExtractor|Font|Group|GroupElement|ImageElement|ImageMaskElement|PathGenerator|TextElement|TextGenerator|Text)(\w+)\b', r'PtxPdfContent_\1_\2'),

            ### PtxPdfForms ########################
            # Types
            (r'\bTPdfRadioButtonField\b', r'TPtxPdfForms_RadioButtonGroup'),
            (r'\bTPdf(CheckBox|ComboBox|ListBox|PushButton)Field\b', r'TPtxPdfForms_\1'),
            (r'\bTPdfForm(Field|FieldType|FieldNode|FieldNodeMap|FieldNodeType)\b', r'TPtxPdfForms_\1'),
            (r'\bePdfChoiceFieldType(Combo|List)BoxField\b', r'ePtxPdfForms_ChoiceFieldType_\1Box'),
            (r'\bePdfChoiceFieldType(\w+)\b', r'ePtxPdfForms_ChoiceFieldType_\1'),
            (r'\bePdfFormFieldTypeRadioButtonField\b', r'ePtxPdfForms_FieldType_RadioButtonGroup'),
            (r'\bePdfFormFieldType(CheckBox|ComboBox|ListBox|PushButton)Field\b', r'ePtxPdfForms_FieldType_\1'),
            (r'\bePdfFormFieldTypeFormField\b', r'ePtxPdfForms_FieldType_Field'),
            (r'\bePdfFormFieldType(\w+)\b', r'ePtxPdfForms_FieldType_\1'),
            (r'\bePdfFormFieldNodeTypeRadioButtonField\b', r'ePtxPdfForms_FieldNodeType_RadioButtonGroup'),
            (r'\bePdfFormFieldNodeType(CheckBox|ComboBox|ListBox|PushButton)Field\b', r'ePtxPdfForms_FieldNodeType_\1'),
            (r'\bePdfFormFieldNodeTypeForm(Field|FieldNode)\b', r'ePtxPdfForms_FieldNodeType_\1'),
            (r'\bePdfFormFieldNodeType(\w+)\b', r'ePtxPdfForms_FieldNodeType_\1'),
            (r'\bePdfTextFieldType(\w+)\b', r'ePtxPdfForms_TextFieldType_\1'),
            (r'\bPdfChoiceItemListAppend\b', r'PtxPdfForms_ChoiceItemList_Add'),
            (r'\bTPdf(ChoiceField|ChoiceFieldType|ChoiceItem|ChoiceItemList|CombTextField|GeneralTextField|RadioButton|RadioButtonList|SignatureField|SignatureFieldList|SubForm|TextField|TextFieldType|Widget|WidgetList)\b', r'TPtxPdfForms_\1'),

            # Functions
            (r'\bPdf(Widget|SignatureField|RadioButton|ChoiceItem)List(\w+)\b', r'PtxPdfForms_\1List_\2'),
            (r'\bPdfFormFieldNodeMap(\w+)\b', r'PtxPdfForms_FieldNodeMap_\1'),
            (r'\bPdf(CheckBox|ComboBox|ListBox)Field(\w+)\b', r'PtxPdfForms_\1_\2'),
            (r'\bPdfForm(Field|FieldNode|FieldNodeMap)(\w+)\b', r'TPtxPdfForms_\1_\2'),
            (r'\bPdf(ChoiceField|ChoiceItemList|ChoiceItem|CombTextField|GeneralTextField|RadioButtonList|RadioButton|SignatureFieldList|SignatureField|SubForm|TextField|WidgetList|Widget)(\w+)\b', r'PtxPdfForms_\1_\2'),

            ### PtxPdfNav ##########################
            # Types
            (r'\bTPdf(Destination|DestinationType|DirectDestination|DirectDestinationType|EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|InternalLink|Link|LocationZoomDestination|NamedDestination|OutlineItem|OutlineItemList|PageDisplay|ViewerSettings|WebLink)\b', r'TPtxPdfNav_\1'),
            (r'\bePdf(Destination|DirectDestination|Link)Type(\w*)\b', r'ePtxPdfNav_\1Type_\2'),

            # Functions
            (r'\bPdfOutlineItemListAppend\b', r'PtxPdfNav_OutlineItemList_Add'),
            (r'\bPdfOutlineItemList(\w+)\b', r'PtxPdfNav_OutlineItemList_\1'),

            (r'\bPdf(DirectDestination|Destination|EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|InternalLink|Link|LocationZoomDestination|NamedDestination|OutlineItemList|OutlineItem|PageDisplay|ViewerSettings|WebLink)(\w+)\b', r'PtxPdfNav_\1_\2'),

            ### PtxSys #############################
            (r'\bTP[dD][fF]StreamDescriptor\b', r'TPtxSys_StreamDescriptor'),
            (r'\bPdfCreateFILEStreamDescriptor\b', r'PtxSysCreateFILEStreamDescriptor'),
            (r'\bTPdfDate\b', r'TPtxSys_Date'),

        ),
        'mark':
        (
            # Unconverted
            (r'(\bPdfClose\b.*)', r'\1 //TODO 3H->4H: Change to PtxPdfContent_TextGenerator_Close, PtxPdfContent_ContentGenerator_Close, PtxPdf_Document_Close, Ptx_Release, or remove'),
            (r'(\bePdfError)(Fatal|Infrastructure|Processing)(\b.*)', r'\1\2\3 //TODO 3H->4H: These error codes cannot occur anymore'),
            (r'(\bePdfPerm)(All|SameAsInput|NoEncryption)(\b.*)', r'\1\2\3 //TODO 3H->4H: These enum values are removed'),
            (r'(\bTPdfPolyDrawingAnnotation\b.*)', r'\1 //TODO 3H->4H: Removed class, maybe change to TPtxPdfAnnots_DrawingAnnotation'),
            (r'(\bTPdfShapeDrawingAnnotation\b.*)', r'\1 //TODO 3H->4H: Removed class, maybe change to TPtxPdfAnnots_DrawingAnnotation'),
            (r'(\bPdfCheckLicense\b.*)', r'\1 //TODO 3H->4H: Removed, license validity is returned in Ptx_Sdk_Initialize'),
            (r'(\bTPdfEncryptionParams\b.*)', r'\1 //TODO 3H->4H: This is now a class TPtxPdf_Encryption'),
            (r'(\bPdfEncryptionParamsInitialize\b.*)', r'\1 //TODO 3H->4H: This is now a class, use PtxPdfContent_Encryption_New'),
            (r'(\bePdfAnnotationType)(Widget|Link|InternalLink|WebLink|EmbeddedPdfLink)(\b.*)', r'\1\2\3 //TODO 3H->4H: Links and widgets are removed from annotation class hierarchy'),
            (r'(\bePdfAnnotationType)(PolyDrawingAnnotation|ShapeDrawingAnnotation)(\b.*)', r'\1\2\3 //TODO 3H->4H: Classes PolyDrawingAnnotation and ShapeDrawingAnnotation are removed'),
            (r'(\bTPdfFillParams\b.*)', r'\1 //TODO 3H->4H: This is now a class TPtxPdfContent_Fill'),
            (r'(\bPdfFillParamsInitialize\b.*)', r'\1 //TODO 3H->4H: This is now a class, use PtxPdfContent_Fill_New'),
            (r'(\bTPdfStrokeParams\b.*)', r'\1 //TODO 3H->4H: This is now a class TPtxPdfContent_Stroke'),
            (r'(\bPdfStrokeParamsInitialize\b.*)', r'\1 //TODO 3H->4H: This is now a class, use PtxPdfContent_Stroke_New'),
            (r'(\bTPdfTransparencyParams\b.*)', r'\1 //TODO 3H->4H: This is now a class TPtxPdfContent_Transparency'),
            (r'(\bPdfTransparencyParamsInitialize\b.*)', r'\1 //TODO 3H->4H: This is now a class, use PtxPdfContent_Transparency_New'),
            (r'(\bePdfColorSpaceDeviceN\b.*)', r'\1 //TODO 3H->4H: Removed DeviceN color space, use TPtxPdfContent_NChannelColorSpace'),
            (r'(\bPdfColorSpaceGetName\b.*)', r'\1 //TODO 3H->4H: This function is removed'),
            (r'(\bPdfContentElementGetTransform\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_AffineTransform now is a struct and must be passed as argument'),
            (r'(\bTPdfCopyOption\b.*)', r'\1 //TODO 3H->4H: Enum changed to class TPtxPdf_PageCopyOption'),
            (r'(\bPdfImageGet(Width|Height)\b.*)', r'\1 //TODO 3H->4H: Substitute by PtxPdfContent_Image_GetSize'),
            (r'(\bPdfImageMaskGet(Width|Height)\b.*)', r'\1 //TODO 3H->4H: Substitute by PtxPdfContent_ImageMask_GetSize'),
            (r'(\bPdfPaintGetTransparency\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_Transparency now is returned directly'),
            (r'(\bPdfPathElementGetStroke\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_Stroke now is returned directly'),
            (r'(\bPdfPathElementGetFill\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_Fill now is returned directly'),
            (r'(\bPdfTextFragmentGetStroke\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_Stroke now is returned directly'),
            (r'(\bPdfTextFragmentGetFill\b.*)', r'\1 //TODO 3H->4H: TPtxPdfContent_Fill now is returned directly'),
            (r'(\bPdfTextGeneratorSetRendering\b.*)', r'\1 //TODO 3H->4H: Substitute by PtxPdfContent_TextGenerator_SetFill and/or PtxPdfContent_TextGenerator_SetStroke'),
            (r'(\bPdfTextField)([GS])(etMaxLength\b.*)', r'\1\2\3 //TODO 3H->4H: Substitute by PtxPdfForms_GeneralTextField_\2etMaxLength or PtxPdfForms_CombTextField_\2etMaxLength'),
            (r'(\bPdfNew)(EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|LocationZoomDestination|WebLink)(\b.*)', r'\1\2\3 //TODO 3H->4H: Function removed, use PtxPdfNav_\2_Create'),
            (r'(\bPdfPageDisplayInitialize\b.*)', r'\1 //TODO 3H->4H: Remove and set field bContinuous of TPtxPdfNav_PageDisplay object manually to TRUE'),
            (r'(\.iYear\s*\+\s*1900.*)', r'\1 //TODO 3H->4H: Remove offset of 1900 from year'),

            # Converted but needs work
            (r'(\bPtx_Sdk_Initialize\b.*)', r'\1 //TODO 3H->4H: Update license key and add a second string argument producerSuffix'),
            (r'(\bPtxPdf_Document_Create\b.*)', r'\1 //TODO 3H->4H: Second argument now is a pointer TPtxPdf_Conformance*'),
            (r'(\bPtxPdf_Document_SetOutputIntent\b.*)', r'\1 //TODO 3H->4H: Maybe need a cast to TPtxPdfContent_IccBasedColorSpace*'),
            (r'(\bPtxPdf_Document_GetPlainEmbeddedFiles\b.*)', r'\1 //TODO 3H->4H: Maybe should be PtxPdf_Document_GetPlainEmbeddedFiles'),
            (r'(\bPtxPdf_Page_GetAnnotations\b.*)', r'\1 //TODO 3H->4H: Maybe also call PtxPdf_Page_GetLinks and PtxPdf_Page_GetFormFieldWidgets'),
            (r'(\bPtxPdf_Page_Copy\b.*)', r'\1 //TODO 3H->4H: Now takes an argument of type TPtxPdf_PageCopyOption*'),
            (r'(\bPtxPdf_Group_CopyFromPage\b.*)', r'\1 //TODO 3H->4H: Now takes an argument of type TPtxPdf_PageCopyOptions*'),
            (r'(\bPtxPdfContent_Paint_Create\b.*)', r'\1 //TODO 3H->4H: Signature has changed.'),
            (r'(\bPtxPdfContent_ColorSpace_CreateProcessColorSpace\b.*)', r'\1 //TODO 3H->4H: Change second argument to type TPtxPdfContent_ProcessColorSpaceType'),
            (r'(\bPtxPdfContent_ContentGenerator_PaintPath\b.*)', r'\1 //TODO 3H->4H: Remove last argument or call PtxPdfContent_ContentGenerator_ClipWithPath'),
            (r'(\bPtxPdfNav_OutlineItem_Copy\b.*)', r'\1 //TODO 3H->4H: Now takes an argument of type TPtxPdfNav_OutlineCopyOptions*'),
            (r'(\bTPtxSys_Date\b.*)', r'\1 //TODO 3H->4H: Remove offset 1900 from field iYear'),
        ),
    },
    'java':
    {
        'ext': ('java', ),
        'sub':
        (
            # Imports
            (r'import\s+com\.pdf_tools\.(pdf\.)?\*', r'''import com.pdf_tools.fourheights.pdftoolbox.*;
import com.pdf_tools.fourheights.pdftoolbox.geometry.*;
import com.pdf_tools.fourheights.pdftoolbox.geometry.real.*;
import com.pdf_tools.fourheights.pdftoolbox.pdf.*;
import com.pdf_tools.fourheights.pdftoolbox.pdf.annotations.*;
import com.pdf_tools.fourheights.pdftoolbox.pdf.content.*;
import com.pdf_tools.fourheights.pdftoolbox.pdf.forms.*;
import com.pdf_tools.fourheights.pdftoolbox.pdf.navigation.*;'''),

            # Methods
            # Sdk
            (r'\b\w+\.setLicenseKey\("[\w-]+"\)', r'Sdk.initialize("", null)'),
            (r'(\w+)\.getProductVersion\(', r'Sdk.getVersion('),

            # Namespace pdftoolbox
            (r'\bErrorCodeException\b', r'PdfToolboxException'),
            (r'\bcom\.pdf_tools\.(PdfToolboxException)\b', r'com.pdf_tools.fourheights.pdftoolbox.\1'),
            (r'\bcom\.pdf_tools\.pdf\.(StringMap)\b', r'com.pdf_tools.fourheights.pdftoolbox.\1'),

            # Namespace pdftoolbox.geometry
            (r'\bTextAlignment\b', r'HorizontalAlignment'),
            (r'\bcom\.pdf_tools\.pdf\.(Rotation|HorizontalAlignment)\b', r'com.pdf_tools.fourheights.pdftoolbox.geometry.\1'),
            (r'\bRotation\.NO_ROTATION\b', r'Rotation.NONE'),

            # Namespace pdftoolbox.geometry.real
            (r'\bTransformation\b', r'AffineTransform'),
            (r'\bcom\.pdf_tools\.(Point|Rectangle|Size|AffineTransform)\b', r'com.pdf_tools.fourheights.pdftoolbox.geometry.real.\1'),
            (r'\bcom\.pdf_tools\.pdf\.(AffineTransform)\b', r'com.pdf_tools.fourheights.pdftoolbox.geometry.real.\1'),
            (r'(\s*)new\s*AffineTransform\(\s*\)', r'\1AffineTransform.getIdentity()'),
            (r'(\s*)new\s*AffineTransform\(\s*(\w+)\s*\)', r'\1new AffineTransform(\2.a, \2.b, \2.c, \2.d, \2.e, \2.f\)'),

            # Namespace pdftoolbox.pdf
            (r'\bConformance\.PDF_(\d)_(\d)\b', r'Conformance.PDF\1\2'),
            (r'\bConformance\.PDFA_(\d)(\w)\b', r'Conformance.PDF_A\1_\2'),
            (r'\bEncryptionParams\b', r'Encryption'),
            (r'\bcom\.pdf_tools\.pdf\.(Conformance|Document|Encryption|FileReference|FileReferenceList|Metadata|Page|PageList|Permission)\b', r'com.pdf_tools.fourheights.pdftoolbox.pdf.\1'),
            (r'\b(\w+)\b\.getOutlineItems\(', r'\1.getOutline('),
            (r'\b(\w+)\b\.getEmbeddedFiles\(', r'\1.getPlainEmbeddedFiles('),
            (r'\bConformance\.UNKNOWN\b', r'null'),
            (r'\b(\w+)\.create(Page|Image|ImageMask|Font|Group|Metadata|FileReference|NamedDestination|OutlineItem|LineAnnotation|PolyLineAnnotation|PolygonAnnotation)\(', r'\2.create(\1, '),
            (r'\b(\w+)\.create(Text|SubForm|GeneralTextField|CombTextField)\(', r'\2.create(\1'),
            (r'\b(\w+)\.create(FileAttachment|FreeText|StickyNote|TextStamp|CustomStamp)Annotation\(', r'\2.create(\1, '),
            (r'\b(\w+)\.create(CheckBox|ComboBox|ListBox)Field\(', r'\2.create(\1'),
            (r'\b(\w+)\.createSystemFont\(', r'Font.createFromSystem(\1, '),
            (r'\b(\w+)\.createDeviceColorSpace\(', r'ColorSpace.createProcessColorSpace(\1, '),
            (r'\b(\w+)\.createICCBasedColorSpace\(', r'IccBasedColorSpace.create(\1, '),
            (r'\b(\w+)\.create(Alpha|Blending|Solid)Paint\(', r'Paint.create(\1, '),
            (r'\b(\w+)\.createRadioButtonField\(', r'RadioButtonGroup.create(\1'),
            (r'\b(\w+)\.createCircleAnnotation\(', r'EllipseAnnotation.create(\1, '),
            (r'\b(\w+)\.createSquareAnnotation\(', r'RectangleAnnotation.create(\1, '),
            (r'\b(\w+)\.createFreeDrawingAnnotation\(', r'InkAnnotation.create(\1, '),
            (r'\b(\w+)\.copy(Annotation|ColorSpace|ContentElement|FileReference|Metadata|OutlineItem|Page|ViewerSettings)\(', r'\2.copy(\1, '),
            (r'\b(\w+)\.copyGroupElementWithoutContent\(', r'GroupElement.copyWithoutContent(\1, '),
            (r'\b(\w+)\.copyPageAsGroup\(', r'Group.copyFromPage(\1, '),
            (r'\b(\w+)\.copyFormFieldNode\(', r'FieldNode.copy(\1, '),
            (r'\b\.setOutputIntent\(ColorSpace\.copy\(', r'.setOutputIntent(IccBasedColorSpace.copy('),

            # Namespace pdftoolbox.pdf.annotations
            (r'\bCircleAnnotation\b', r'EllipseAnnotation'),
            (r'\bFreeDrawingAnnotation\b', r'InkAnnotation'),
            (r'\bSquareAnnotation\b', r'RectangleAnnotation'),
            (r'\bAnnotation(LineEnding|Popup)\b', r'\1'),
            (r'\b(CustomStamp|FileAttachment|FreeText|Highlight|Squiggly|Stamp|StickyNote|StrikeThrough|TextMarkup|TextStamp|Underline)Annotation\b', r'\1'),
            (r'\bcom\.pdf_tools\.pdf\.(Annotation|AnnotationList|CustomStamp|DrawingAnnotation|FileAttachment|FileAttachmentIcon|InkAnnotation|FreeText|Highlight|LineAnnotation|LineEnding|MarkupAnnotation|MarkupInfo|MarkupInfoList|PolyLineAnnotation|PolygonAnnotation|Popup|RectangleAnnotation|Squiggly|Stamp|StickyNote|StrikeThrough|TextMarkup|TextStamp|Underline)\b', r'com.pdf_tools.fourheights.pdftoolbox.pdf.annotations.\1'),

            # Namespace pdftoolbox.pdf.content
            (r'\bDeviceColorSpaceType\b', r'ProcessColorSpaceType'),
            (r'\b(Encryption|Fill|Stroke|Transparency)Params\b', r'\1'),
            (r'\bcom\.pdf_tools\.pdf\.(BlendMode|ColorSpace|Content|ContentElement|ContentExtractor|ContentGenerator|Encryption|Fill|Font|Group|GroupElement|Image|ImageElement|ImageMask|ImageMaskElement|InsideRule|LineCapStyle|LineJoinStyle|Paint|Path|PathElement|PathGenerator|ProcessColorSpaceType|ShadingElement|Stroke|Text|TextElement|TextFragment|TextGenerator|Transparency)\b', r'com.pdf_tools.fourheights.pdftoolbox.pdf.content.\1'),
            (r'\b(\w+)\.getComponents\(', r'\1.getComponentCount('),
            (r'\b(\w+)\.([gs])etFillRule\(', r'\1.\2etInsideRule('),
            (r'\bnew\s+(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.content\.)?Fill\(\s*([^),]+),\s*(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.content\.)?InsideRule\.NONZERO_WINDING_NUMBER\s*\)', r'new \1Fill(\2)'),
            (r'\b(\w+)\.getCharWidth\(', r'\1.getCharacterWidth('),
            (r'\b(\w+)\.setCharSpacing\(', r'\1.setCharacterSpacing('),
            (r'\b(\w+)\.getUnicodeString\(', r'\1.getText('),
            (r'\b(\w+)\.rotateAround\(', r'\1.rotate('),

            # Namespace pdftoolbox.pdf.forms
            (r'\bRadioButtonField\b', r'RadioButtonGroup'),
            (r'\b(CheckBox|ComboBox|ListBox|PushButton)Field\b', r'\1'),
            (r'\bForm(Field|FieldNode|FieldNodeMap)\b', r'\1'),
            (r'\bcom\.pdf_tools\.pdf\.(CheckBox|ChoiceField|ChoiceItem|ChoiceItemList|ComboBox|CombTextField|Field|FieldNode|FieldNodeMap|GeneralTextField|ListBox|PushButton|RadioButton|RadioButtonGroup|RadioButtonList|SignatureField|SignatureFieldList|TextField|Widget|WidgetList)\b', r'com.pdf_tools.fourheights.pdftoolbox.pdf.forms.\1'),
            (r'([^!]\s*)(\w+)\.getDoPrint\((.*)', r'\1!\2.getNoPrint(\3'),
            (r'!\s*(\w+)\.getDoPrint\((.*)', r'\1.getNoPrint(\2'),

            # Namespace pdftoolbox.pdf.navigation
            (r'\bcom\.pdf_tools\.pdf\.(Destination|DirectDestination|EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|InternalLink|Link|LocationZoomDestination|NamedDestination|OutlineItem|OutlineItemList|PageDisplay|ViewerNavigationPane|ViewerSettings|WebLink)\b', r'com.pdf_tools.fourheights.pdftoolbox.pdf.navigation.\1'),

            # Namespace pdftoolbox.sys
            (r'\bcom\.pdf_tools\.(File|Memory)?Stream\b', r'com.pdf_tools.fourheights.pdftoolbox.sys.\1Stream'),
        ),
        'mark':
        (
            # Unconverted
            (r'(\bErrorCode\b.*)', r'\1 //TODO 3H->4H: Substituted by new classes extending PdfToolboxException'),
            (r'(\bCopyOption\b.*)', r'\1 //TODO 3H->4H: Substitute by new class PageCopyOptions or Navigation.OutlineCopyOptions'),
            (r'\b(Poly|Shape)(DrawingAnnotation\b.*)', r'\1\2 //TODO 3H->4H: Removed class, use base class DrawingAnnotation'),
            (r'(\.get)(Type|Name)(\(.*)', r'\1\2\3 //TODO 3H->4H: Removed method'),
            (r'(\bColorSpaceType\b.*)', r'\1 //TODO 3H->4H: Removed enum.'),
            (r'(\bnew\s+)(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.content\.)?(Fill|Stroke|Transparency)(\(\s*[^),]+,.*)', r'\1\2\3\4 //TODO 3H->4H: Constructor arguments changed.'),
            (r'(\.get)(Width|Height)(\(.*)', r'\1\2\3 //TODO 3H->4H: If this is an Image or ImageMaks object: substitute by getSize()'),
            (r'(\bnew\s+)(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.content\.)?(Path\(.*)', r'\1\2\3 //TODO 3H->4H: InsideRule is no longer a property of Path, but is applied when painting/clipping a path.'),
            (r'\b(\w+\.setRendering\(.*)', r'\1 //TODO 3H->4H: Removed method, use setPaint and/or setStroke'),
            (r'\b(\w+\.[gs]etCanToggleOff\(.*)', r'\1 //TODO 3H->4H: Removed method'),
            (r'(\bnew\s+)(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.navigation\.)?(EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|LocationZoomDestination|WebLink)(\(.*)', r'\1\2\3\4 //TODO 3H->4H: Removed constructor, use \3.create'),
            (r'(\bnew\s+)(com\.pdf_tools\.fourheights\.pdftoolbox\.pdf\.navigation\.)?(PageDisplay\(.*)', r'\1\2\3 //TODO 3H->4H: Default value for field continuous has changed from true to false.'),
            (r'(\w+\.setOutputIntent\(.*)', r'\1 //TODO 3H->4H: Maybe convert to IccBasedColorSpace'),

            # Converted but needs work
            (r'(import com\.pdf_tools\.fourheights\.pdftoolbox\.\*;)(.*)', r'\1 //TODO 3H->4H: Check imports\2'),
            (r'(Sdk\.initialize\("", null\).*)', r'\1 //TODO 3H->4H: Maybe need to import com.pdf_tools.fourheights.pdftoolbox.Sdk, give meaningful arguments'),
            (r'(Sdk\.getVersion\(.*)', r'\1 //TODO 3H->4H: Maybe need to import com.pdf_tools.fourheights.pdftoolbox.Sdk'),
            (r'(\w+\.getPlainEmbeddedFiles\(.*)', r'\1 //TODO 3H->4H: Check'),
            (r'(Paint\.create\(.*)', r'\1 //TODO 3H->4H: Signature has changed'),
            (r'(Page\.copy\(.*)', r'\1 //TODO 3H->4H: Now takes an argument of type PageCopyOptions'),
        ),
    },
    'net':
    {
        'ext': ('cs', ),
        'sub':
        (
            # Usings
            (r'^\s*using\s+PdfTools\s*;.*', r''),
            (r'^\s*using\s+PdfTools\.Pdf\s*;', '''using PdfTools.FourHeights.PdfToolbox;
using PdfTools.FourHeights.PdfToolbox.Geometry;
using PdfTools.FourHeights.PdfToolbox.Geometry.Real;
using PdfTools.FourHeights.PdfToolbox.Pdf;
using PdfTools.FourHeights.PdfToolbox.Pdf.Annotations;
using PdfTools.FourHeights.PdfToolbox.Pdf.Content;
using PdfTools.FourHeights.PdfToolbox.Pdf.Forms;
using PdfTools.FourHeights.PdfToolbox.Pdf.Navigation;'''),

            # Sdk
            (r'\b\w+\.LicenseKey\s*=.*', r'Sdk.Initialize("", null);'),
            (r'(\w+)\.ProductVersion\b', r'Sdk.Version'),

            # Namespace PdfToolbox
            (r'\bErrorCodeException\b', r'PdfToolboxException'),
            (r'\bPdfTools\.(PdfToolboxException)\b', r'PdfTools.FourHeights.PdfToolbox.\1'),
            (r'\bPdfTools\.pdf\.(StringMap)\b', r'PdfTools.FourHeights.PdfToolbox.\1'),

            # Namespace PdfToolbox.geometry
            (r'\bTextAlignment\b', r'HorizontalAlignment'),
            (r'\bPdfTools\.pdf\.(Rotation|HorizontalAlignment)\b', r'PdfTools.FourHeights.PdfToolbox.geometry.\1'),
            (r'\bRotation\.NoRotation\b', r'Rotation.None'),

            # Namespace PdfToolbox.geometry.real
            (r'\bTransformation\b', r'AffineTransform'),
            (r'\bPdfTools\.(Point|Rectangle|Size|AffineTransform)\b', r'PdfTools.FourHeights.PdfToolbox.geometry.real.\1'),
            (r'\bPdfTools\.Pdf\.(AffineTransform)\b', r'PdfTools.FourHeights.PdfToolbox.geometry.real.\1'),
            (r'(\s*)new\s*AffineTransform\(\s*\)', r'\1AffineTransform.Identity'),
            (r'(\s*)new\s*AffineTransform\(\s*(\w+)\s*\)', r'\1new AffineTransform(\2.A, \2.B, \2.C, \2.D, \2.E, \2.F\)'),

            # Namespace PdfToolbox.pdf
            (r'\bEncryptionParams\b', r'Encryption'),
            (r'\bPdfTools\.Pdf\.(Conformance|Document|Encryption|FileReference|FileReferenceList|Metadata|Page|PageList|Permission)\b', r'PdfTools.FourHeights.PdfToolbox.Pdf.\1'),
            (r'\b(\w+)\b\.OutlineItems\b', r'\1.Outline'),
            (r'\b(\w+)\b\.EmbeddedFiles\b', r'\1.PlainEmbeddedFiles'),
            (r'\bConformance\.Unknown\b', r'null'),
            (r'\b(\w+)\.Create(Page|Image|ImageMask|Font|Group|Metadata|FileReference|NamedDestination|OutlineItem|LineAnnotation|PolyLineAnnotation|PolygonAnnotation)\(', r'\2.Create(\1, '),
            (r'\b(\w+)\.Create(Text|SubForm|GeneralTextField|CombTextField)\(', r'\2.Create(\1'),
            (r'\b(\w+)\.Create(FileAttachment|FreeText|StickyNote|TextStamp|CustomStamp)Annotation\(', r'\2.Create(\1, '),
            (r'\b(\w+)\.Create(CheckBox|ComboBox|ListBox)Field\(', r'\2.Create(\1'),
            (r'\b(\w+)\.CreateSystemFont\(', r'Font.CreateFromSystem(\1, '),
            (r'\b(\w+)\.CreateDeviceColorSpace\(', r'ColorSpace.CreateProcessColorSpace(\1, '),
            (r'\b(\w+)\.CreateICCBasedColorSpace\(', r'IccBasedColorSpace.Create(\1, '),
            (r'\b(\w+)\.Create(Alpha|Blending|Solid)Paint\(', r'Paint.Create(\1, '),
            (r'\b(\w+)\.CreateRadioButtonField\(', r'RadioButtonGroup.Create(\1'),
            (r'\b(\w+)\.CreateCircleAnnotation\(', r'EllipseAnnotation.Create(\1, '),
            (r'\b(\w+)\.CreateSquareAnnotation\(', r'RectangleAnnotation.Create(\1, '),
            (r'\b(\w+)\.CreateFreeDrawingAnnotation\(', r'InkAnnotation.Create(\1, '),
            (r'\b(\w+)\.Copy(Annotation|ColorSpace|ContentElement|FileReference|Metadata|OutlineItem|Page|ViewerSettings)\(', r'\2.Copy(\1, '),
            (r'\b(\w+)\.CopyGroupElementWithoutContent\(', r'GroupElement.CopyWithoutContent(\1, '),
            (r'\b(\w+)\.CopyPageAsGroup\(', r'Group.CopyFromPage(\1, '),
            (r'\b(\w+)\.CopyFormFieldNode\(', r'FieldNode.Copy(\1, '),
            (r'\b\.OutputIntent\s*=\s*ColorSpace\.Copy\(', r'.OutputIntent = IccBasedColorSpace.Copy('),

            # Namespace PdfToolbox.Pdf.Annotations
            (r'\bCircleAnnotation\b', r'EllipseAnnotation'),
            (r'\bFreeDrawingAnnotation\b', r'InkAnnotation'),
            (r'\bSquareAnnotation\b', r'RectangleAnnotation'),
            (r'\bAnnotation(LineEnding|Popup)\b', r'\1'),
            (r'\b(CustomStamp|FileAttachment|FreeText|Highlight|Squiggly|Stamp|StickyNote|StrikeThrough|TextMarkup|TextStamp|Underline)Annotation\b', r'\1'),
            (r'\bPdfTools\.Pdf\.(Annotation|AnnotationList|CustomStamp|DrawingAnnotation|FileAttachment|FileAttachmentIcon|InkAnnotation|FreeText|Highlight|LineAnnotation|LineEnding|MarkupAnnotation|MarkupInfo|MarkupInfoList|PolyLineAnnotation|PolygonAnnotation|Popup|RectangleAnnotation|Squiggly|Stamp|StickyNote|StrikeThrough|TextMarkup|TextStamp|Underline)\b', r'PdfTools.FourHeights.PdfToolbox.Pdf.Annotations.\1'),

            # Namespace PdfToolbox.Pdf.Content
            (r'\bDeviceColorSpaceType\b', r'ProcessColorSpaceType'),
            (r'\b(Encryption|Fill|Stroke|Transparency)Params\b', r'\1'),
            (r'\bPdfTools\.Pdf\.(BlendMode|ColorSpace|Content|ContentElement|ContentExtractor|ContentGenerator|Encryption|Fill|Font|Group|GroupElement|Image|ImageElement|ImageMask|ImageMaskElement|InsideRule|LineCapStyle|LineJoinStyle|Paint|Path|PathElement|PathGenerator|ProcessColorSpaceType|ShadingElement|Stroke|Text|TextElement|TextFragment|TextGenerator|Transparency)\b', r'PdfTools.FourHeights.PdfToolbox.Pdf.Content.\1'),
            (r'\b(\w+)\.Components\b', r'\1.ComponentCount'),
            (r'\b(\w+)\.FillRule\b', r'\1.InsideRule'),
            (r'\bnew\s+(PdfTools\.FourHeights\.PdfToolbox\.Pdf\.Content\.)?Fill\(\s*([^),]+),\s*(PdfTools\.FourHeights\.PdfToolbox\.Pdf\.Content\.)?InsideRule\.NonzeroWindingNumber\s*\)', r'new \1Fill(\2)'),
            (r'\b(\w+)\.CharWidth\b', r'\1.CharacterWidth'),
            (r'\b(\w+)\.CharSpacing\b', r'\1.CharacterSpacing'),
            (r'\b(\w+)\.UnicodeString\b', r'\1.Text'),
            (r'\b(\w+)\.RotateAround\(', r'\1.Rotate('),
            (r'\bProcessColorSpaceType\.RGB\b', r'ProcessColorSpaceType.Rgb'),
            (r'\bProcessColorSpaceType\.CMYK\b', r'ProcessColorSpaceType.Cmyk'),

            # Namespace PdfToolbox.Pdf.Forms
            (r'\bRadioButtonField\b', r'RadioButtonGroup'),
            (r'\b(CheckBox|ComboBox|ListBox|PushButton)Field\b', r'\1'),
            (r'\bForm(Field|FieldNode|FieldNodeMap)\b', r'\1'),
            (r'\bPdfTools\.Pdf\.(CheckBox|ChoiceField|ChoiceItem|ChoiceItemList|ComboBox|CombTextField|Field|FieldNode|FieldNodeMap|GeneralTextField|ListBox|PushButton|RadioButton|RadioButtonGroup|RadioButtonList|SignatureField|SignatureFieldList|TextField|Widget|WidgetList)\b', r'PdfTools.FourHeights.PdfToolbox.Pdf.Forms.\1'),
            (r'([^!]\s*)(\w+)\.DoPrint\b(.*)', r'\1!\2.NoPrint\3'),
            (r'!\s*(\w+)\.DoPrint\b(.*)', r'\1.NoPrint\2'),

            # Namespace PdfToolbox.Pdf.Navigation
            (r'\bPdfTools\.Pdf\.(Destination|DirectDestination|EmbeddedPdfLink|FitHeightDestination|FitPageDestination|FitRectangleDestination|FitWidthDestination|InternalLink|Link|LocationZoomDestination|NamedDestination|OutlineItem|OutlineItemList|PageDisplay|ViewerNavigationPane|ViewerSettings|WebLink)\b', r'PdfTools.FourHeights.PdfToolbox.Pdf.Navigation.\1'),
        ),
        'mark':
        (
            (r'(using PdfTools.FourHeights.PdfToolbox;)(.*)', r'\1 //TODO 3H->4H: Check usings\2'),
            (r'(Sdk\.Initialize.*)', r'\1 //TODO 3H->4H: Insert new license key'),
            (r'(\bCopyOption\b[^\.].*)', r'\1 //TODO 3H->4H: Substitute by PageCopyOptions or OutlineCopyOptions', ),
            (r'(\w+\.OutputIntent\s*=.*)', r'\1 //TODO 3H->4H: Maybe convert to IccBasedColorSpace with "as IccBasedColorSpace"'),
            (r'(\w+\.PlainEmbeddedFiles.*)', r'\1 //TODO 3H->4H: Check'),
        ),
    },
}

if __name__ == "__main__":
    main()