Example #1
0
uint Settings::versionMinor()
{
    // Don't cache this value; ignore the group
    create_qsettings;
    // '0' means new configuration, anything else indicates an existing configuration.  Application
    // initialization should check this value and manage upgrades/downgrades, e.g. in Core::Core()
    // and QtUiApplication::init().
    uint verMinor = s.value("Config/VersionMinor", 0).toUInt();

    // As previous Quassel versions didn't implement this, we need to check if any settings other
    // than Config/Version exist.  If so, assume it's version 1.
    if (verMinor == 0 && s.allKeys().count() > 1) {
        // More than 1 key exists, but version's never been set.  Assume and set version 1.
        setVersionMinor(VERSION_MINOR_INITIAL);
        return VERSION_MINOR_INITIAL;
    } else {
        return verMinor;
    }
}
Example #2
0
static int writeFontInfo(ufwCtx h, abfTopDict *top) {
    char buffer[FILENAME_MAX];
    char buffer2[FILENAME_MAX];
    abfFontDict *fontDict0;
    abfPrivateDict *privateDict;
    int i;

    if (h->lastiFD != ABF_UNSET_INT)
        fontDict0 = &(top->FDArray.array[h->lastiFD]);
    else
        fontDict0 = &(top->FDArray.array[0]);
    privateDict = &(fontDict0->Private);

    /* Set error handler */
    DURING_EX(h->err.env)

    h->state = 1; /* Indicates writing to dst stream */

    /* Open fontinfo.plist file as dst stream */

    sprintf(buffer, "%s", "fontinfo.plist");
    h->cb.stm.clientFileName = buffer;
    h->stm.dst = h->cb.stm.open(&h->cb.stm, UFW_DST_STREAM_ID, 0);
    if (h->stm.dst == NULL)
        fatal(h, ufwErrDstStream);

    writeLine(h, XML_HEADER);
    writeLine(h, PLIST_DTD_HEADER);
    writeLine(h, "<plist version=\"1.0\">");
    writeLine(h, "<dict>");

    /* This is what I care about the most. Add the rest in the order of the
     UFO 3 spec. */
    writeLine(h, "\t<key>postscriptFontName</key>");
    if (top->sup.flags & ABF_CID_FONT) {
        sprintf(buffer, "\t<string>%s</string>", top->cid.CIDFontName.ptr);
        writeLine(h, buffer);
        setStyleName(buffer2, top->cid.CIDFontName.ptr);
        writeLine(h, "\t<key>styleName</key>");
        sprintf(buffer, "\t<string>%s</string>", buffer2);
        writeLine(h, buffer);
    } else {
        sprintf(buffer, "\t<string>%s</string>", fontDict0->FontName.ptr);
        writeLine(h, buffer);
        setStyleName(buffer2, fontDict0->FontName.ptr);
        writeLine(h, "\t<key>styleName</key>");
        sprintf(buffer, "\t<string>%s</string>", buffer2);
        writeLine(h, buffer);
    }

    if (top->FamilyName.ptr != NULL) {
        writeLine(h, "\t<key>familyName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->FamilyName.ptr);
        writeLine(h, buffer);
    }

    if (top->sup.flags & ABF_CID_FONT) {
        if (top->cid.CIDFontVersion != 0) {
            char versionStr[32];
            sprintf(versionStr, "%.3f", top->cid.CIDFontVersion);
            setVersionMajor(buffer2, versionStr);
            writeLine(h, "\t<key>versionMajor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
            setVersionMinor(buffer2, versionStr);
            writeLine(h, "\t<key>versionMinor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
        }
    } else {
        if (top->version.ptr != NULL) {
            setVersionMajor(buffer2, top->version.ptr);
            writeLine(h, "\t<key>versionMajor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
            setVersionMinor(buffer2, top->version.ptr);
            writeLine(h, "\t<key>versionMinor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
        }
    }

    if (top->Copyright.ptr != NULL) {
        writeLine(h, "\t<key>copyright</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Copyright.ptr);
        writeLine(h, buffer);
    }

    if (top->Notice.ptr != NULL) {
        writeLine(h, "\t<key>trademark</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Notice.ptr);
        writeLine(h, buffer);
    }

    writeLine(h, "\t<key>unitsPerEm</key>");
    if (fontDict0->FontMatrix.cnt > 0) {
        sprintf(buffer, "\t<integer>%d</integer>",
                (int)round(1.0 / fontDict0->FontMatrix.array[0]));
        writeLine(h, buffer);

    } else {
        writeLine(h, "\t<integer>1000</integer>");
    }

    if (top->ItalicAngle != cff_DFLT_ItalicAngle) {
        writeLine(h, "\t<key>italicAngle</key>");
        sprintf(buffer, "\t<real>%.8f</real>", top->ItalicAngle);
        writeLine(h, buffer);
    }

    /* Now for all the other PostScript-specific UFO data */
    if (top->FullName.ptr != NULL) {
        writeLine(h, "\t<key>postscriptFullName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->FullName.ptr);
        writeLine(h, buffer);
    }

    if (top->Weight.ptr != NULL) {
        writeLine(h, "\t<key>postscriptWeightName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Weight.ptr);
        writeLine(h, buffer);
    }

    if (top->UnderlinePosition != cff_DFLT_UnderlinePosition) {
        writeLine(h, "\t<key>postscriptUnderlinePosition</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)round(0.5 + top->UnderlinePosition));
        writeLine(h, buffer);
    }

    if (top->UnderlineThickness != cff_DFLT_UnderlineThickness) {
        writeLine(h, "\t<key>postscriptUnderlineThickness</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)round(0.5 + top->UnderlineThickness));
        writeLine(h, buffer);
    }

    if ((top->isFixedPitch != cff_DFLT_isFixedPitch) && (top->isFixedPitch > 0)) {
        writeLine(h, "\t<key>postscriptIsFixedPitch</key>");
        writeLine(h, "\t<true/>");
    }

    /* All the Blue values */
    if (privateDict->BlueValues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptBlueValues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->BlueValues.cnt; i++) {
            float stem = privateDict->BlueValues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->OtherBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptOtherBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->OtherBlues.cnt; i++) {
            float stem = privateDict->OtherBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->FamilyBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptFamilyBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->FamilyBlues.cnt; i++) {
            float stem = privateDict->FamilyBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->FamilyOtherBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptFamilyOtherBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->FamilyOtherBlues.cnt; i++) {
            float stem = privateDict->FamilyOtherBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->StemSnapH.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptStemSnapH</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->StemSnapH.cnt; i++) {
            float stem = privateDict->StemSnapH.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    } else if (privateDict->StdHW != ABF_UNSET_REAL) {
        float stem = privateDict->StdHW;
        writeLine(h, "\t<key>postscriptStemSnapH</key>");
        writeLine(h, "\t<array>");
        if (stem == ((int)stem))
            sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
        else
            sprintf(buffer, "\t\t<real>%.2f</real>", stem);
        writeLine(h, buffer);
        writeLine(h, "\t</array>");
    }

    if (privateDict->StemSnapV.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptStemSnapV</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->StemSnapV.cnt; i++) {
            float stem = privateDict->StemSnapV.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    } else if (privateDict->StdVW != ABF_UNSET_REAL) {
        float stem = privateDict->StdVW;
        writeLine(h, "\t<key>postscriptStemSnapV</key>");
        writeLine(h, "\t<array>");
        if (stem == ((int)stem))
            sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
        else
            sprintf(buffer, "\t\t<real>%.2f</real>", stem);
        writeLine(h, buffer);
        writeLine(h, "\t</array>");
    }

    if (privateDict->BlueScale != ABF_UNSET_REAL) {
        char *p;
        char valueBuffer[50];
        /* 8 places is as good as it gets when converting ASCII real numbers->float-> ASCII real numbers, as happens to all the  PrivateDict values.*/
        sprintf(valueBuffer, "%.8f", privateDict->BlueScale);
        p = strchr(valueBuffer, '.');
        if (p != NULL) {
            /* Have decimal point. Remove trailing zeroes.*/
            int l = strlen(p);
            p += l - 1;
            while (*p == '0') {
                *p = '\0';
                p--;
            }
            if (*p == '.') {
                *p = '\0';
            }
        }

        writeLine(h, "\t<key>postscriptBlueScale</key>");
        sprintf(buffer, "\t<real>%s</real>", valueBuffer);
        writeLine(h, buffer);
    }

    if (privateDict->BlueShift != ABF_UNSET_REAL) {
        writeLine(h, "\t<key>postscriptBlueShift</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)(0.5 + privateDict->BlueShift));
        writeLine(h, buffer);
    }

    if (privateDict->BlueFuzz != ABF_UNSET_REAL) {
        writeLine(h, "\t<key>postscriptBlueFuzz</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)(0.5 + privateDict->BlueFuzz));
        writeLine(h, buffer);
    }

    if ((privateDict->ForceBold != ABF_UNSET_INT) && (privateDict->ForceBold > 0)) {
        writeLine(h, "\t<key>postscriptForceBold</key>");
        writeLine(h, "\t<true/>");
    }

    /* Finish the file */
    writeLine(h, "</dict>");
    writeLine(h, "</plist>");
    flushBuf(h);

    /* Close dst stream */
    if (h->cb.stm.close(&h->cb.stm, h->stm.dst) == -1)
        return ufwErrDstStream;

    HANDLER
    if (h->stm.dst)
        h->cb.stm.close(&h->cb.stm, h->stm.dst);
    return Exception.Code;

    END_HANDLER

    return ufwSuccess;
}