コード例 #1
0
ファイル: glyphwriting.cpp プロジェクト: vadz/wxpdfdoc
void glyphwriting()
{
    double scaleFactor = 0.15;
    wxFileInputStream sampleFile(wxT("glyphsample.txt"));
    if (sampleFile.Ok())
    {
        wxTextInputStream text(sampleFile);

        wxPdfDocument pdf;
        pdf.AddPage();
        pdf.SetFont(wxT("helvetica"), wxT(""), 16);
        pdf.Text(10, 10, wxT("Direct glyph writing (sample text from the ICU project)"));
        pdf.SetFont(wxT("helvetica"), wxT(""), 10);
        pdf.Text(10, 15, wxT("Unicode text based on complex scripts may be preprocessed for PDF output with ICU or similar tools."));

        double xp = 0, yp = 0;
        double x, y;
        long gid, count;
        wxString line, token;
        wxPdfArrayDouble xOffsets;
        wxPdfArrayDouble yOffsets;
        wxPdfArrayUint32 gNumbers;
        while (!sampleFile.Eof())
        {
            line = text.ReadLine();
            line.Trim();
            wxStringTokenizer tkz(line, wxT(" "));
            int n = (int) tkz.CountTokens();
            if (n == 1)
            {
                wxStringTokenizer tkz2(line, wxT("="));
                wxString fontName = tkz2.GetNextToken();
                wxString fontFile = tkz2.GetNextToken();
                pdf.AddFont(fontName, wxT(""), fontFile);
            }
            else if (n == 5)
            {
                // Write glyph array if not empty
                if (gNumbers.GetCount() > 0)
                {
                    pdf.SetXY(xp+10, yp+20);
                    pdf.WriteGlyphArray(xOffsets, yOffsets, gNumbers);
                    xOffsets.Empty();
                    yOffsets.Empty();
                    gNumbers.Empty();
                }
                // Start a new run
                token = tkz.GetNextToken();
                token.ToLong(&gid);
                token = tkz.GetNextToken();
                xp = scaleFactor * wxPdfUtility::String2Double(token);
                token = tkz.GetNextToken();
                yp = scaleFactor * wxPdfUtility::String2Double(token);
                token = tkz.GetNextToken();
                token.ToLong(&count);
                token = tkz.GetNextToken();
                if (count > 0)
                {
                    pdf.SetFont(token, wxT(""), 14);
                }
            }
            else if (n == 3)
            {
                // glyph number, x offset, y offset
                token = tkz.GetNextToken();
                token.ToLong(&gid);
                token = tkz.GetNextToken();
                x = scaleFactor * wxPdfUtility::String2Double(token);
                token = tkz.GetNextToken();
                y = scaleFactor * wxPdfUtility::String2Double(token);
                xOffsets.Add(x);
                yOffsets.Add(y);
                gNumbers.Add(gid);
            }
        }

        pdf.SaveAsFile(wxT("glyphwriting.pdf"));
    }
    else
    {
        wxLogMessage(_("Error: Unable to read 'glyphsample.txt'."));
        return;
    }
}
コード例 #2
0
ファイル: utils.cpp プロジェクト: silv3rm00n/Turbotrace
/**
    @brief
    Analyse the raw whois data to find out useful things like isp , ip range etc.
*/
whois_analysis utils::analyse_whois(wxString whois_data)
{
    whois_analysis who;

    //Apnic format analysis
    if(whois_data.Find("whois.apnic.net") != wxNOT_FOUND)
    {
        who.rir = "APNIC";

        wxStringTokenizer tkz(whois_data, wxT("\n"));

        while ( tkz.HasMoreTokens() )
        {
            wxString token = tkz.GetNextToken();

            // process token here
            if(token.Find("netname") != wxNOT_FOUND)
            {
                wxStringTokenizer tkz2(token , wxT(":"));
                while ( tkz2.HasMoreTokens() )
                {
                    wxString isp = tkz2.GetNextToken();
                    isp.Trim(false).Trim();
                    who.isp = isp;

                    wxPrintf("ISP is : %s" , isp);
                }

            }
        }
    }

    //ARIN format analysis
    else if(whois_data.Find("whois.arin.net") != wxNOT_FOUND)
    {
        who.rir = "ARIN";

        wxStringTokenizer tkz(whois_data, wxT("\n"));

        while ( tkz.HasMoreTokens() )
        {
            wxString token = tkz.GetNextToken();

            // process token here
            if(token.Find("NetName") != wxNOT_FOUND)
            {
                wxStringTokenizer tkz2(token , wxT(":"));
                while ( tkz2.HasMoreTokens() )
                {
                    wxString isp = tkz2.GetNextToken();
                    isp.Trim(false).Trim();
                    who.isp = isp;

                    wxPrintf("ISP is : %s" , isp);
                }
            }
        }
    }

    //RIPE format
    else if(whois_data.Find("ripe.net") != wxNOT_FOUND)
    {
        who.rir = "RIPE";

        wxStringTokenizer tkz(whois_data, wxT("\n"));

        while ( tkz.HasMoreTokens() )
        {
            wxString token = tkz.GetNextToken();

            // process token here
            if(token.Find("netname") != wxNOT_FOUND)
            {
                wxStringTokenizer tkz2(token , wxT(":"));
                while ( tkz2.HasMoreTokens() )
                {
                    wxString isp = tkz2.GetNextToken();
                    isp.Trim(false).Trim();
                    who.isp = isp;

                    wxPrintf("ISP is : %s" , isp);
                }
            }
        }
    }

    //LACNIC Format ??



    return who;
}