예제 #1
0
static CharInfoRec *
CIDGetCharMetrics(FontPtr pFont, FontInfo *fi, unsigned int charcode, double sxmult)
{
    CharInfoPtr cp;
    Metrics *p, node;
    unsigned int cidcode;

    cidcode = node.code = getCID(pFont, charcode);
    if ((cidcode < fi->nChars) && (cidcode == fi->metrics[cidcode].code))
        p = &fi->metrics[cidcode];
    else
        p = (Metrics *)bsearch(&node, fi->metrics, fi->nChars, sizeof(Metrics), node_compare);

    if (!p)
        p = &fi->metrics[0];

    if (!(cp = (CharInfoRec *)Xalloc(sizeof(CharInfoRec))))
        return NULL;
    bzero(cp, sizeof(CharInfoRec));

    /* indicate that character bitmap is not defined */
    cp->bits = (char *)CID_BITMAP_UNDEFINED;


    /* get metric data for this CID code from the CID AFM file */
    cp->metrics.leftSideBearing =
        floor(p->charBBox.llx / sxmult + 0.5);
    cp->metrics.rightSideBearing =
        floor(p->charBBox.urx / sxmult + 0.5);
    cp->metrics.characterWidth = floor(p->wx / sxmult + 0.5);
    cp->metrics.ascent = floor(p->charBBox.ury / sxmult + 0.5);
    cp->metrics.descent = -floor(p->charBBox.lly / sxmult + 0.5);

    cp->metrics.attributes = p->wx;

    return cp;
}
예제 #2
0
unsigned long AqueousNaClGenerator::readPhaseSpace(ParticleContainer* particleContainer,
		std::list<ChemicalPotential>* lmu, Domain* domain, DomainDecompBase* domainDecomp) {

	Timer inputTimer;
	inputTimer.start();
	_logger->info() << "Reading phase space file (AqueousNaClGenerator)." << endl;

	int numMoleculesPerDimension = round(pow((double) _numMolecules, 1./3.));
	int numIons = round(0.01812415 * (double) _numMolecules);
	_logger->info() << "Generating " << numIons << " of Na+ and Cl-" << endl;
	Ion* ions = new Ion[2 * numIons];
	for (int i = 0; i < numIons; i++) {
		ions[i].cid = 1;
		do {
			for (int j = 0; j < 3; j++) {
				ions[i].position[j] = (double) rand() / ((double) RAND_MAX) * (numMoleculesPerDimension-1);
			}
			std::cout << "Testing " << ions[i].position[0] << "," << ions[i].position[1] << "," << ions[i].position[2] << endl;
		} while (isNearIon(ions, i));
		std::cout << "Generate Na+ at " << ions[i].position[0] << "," << ions[i].position[1] << "," << ions[i].position[2] << ";" << endl;
	}
	for (int i = numIons; i < 2*numIons; i++) {
		ions[i].cid = 2;
		do {
			for (int j = 0; j < 3; j++) {
				ions[i].position[j] = (double) rand() / ((double) RAND_MAX) * (numMoleculesPerDimension-1);
			}
			std::cout << "Testing " << ions[i].position[0] << "," << ions[i].position[1] << "," << ions[i].position[2] << endl;
		} while (isNearIon(ions, i));
		std::cout << "Generate Na+ at " << ions[i].position[0] << "," << ions[i].position[1] << "," << ions[i].position[2] << ";" << endl;
	}

	unsigned long int id = 1;
	double spacing = _simBoxLength / numMoleculesPerDimension;
	_logger->info() << "SimBoxLength=" << _simBoxLength << " spacing=" << spacing << endl;
	double origin = spacing / 2.; // origin of the first DrawableMolecule

	// only for console output
	double percentage = 1.0 / numMoleculesPerDimension * 100.0;
	int percentageRead = 0;

	for (int i = 0; i < numMoleculesPerDimension; i++) {
		for (int j = 0; j < numMoleculesPerDimension; j++) {
			for (int k = 0; k < numMoleculesPerDimension; k++) {

				double x = origin + i * spacing;
				double y = origin + j * spacing;
				double z = origin + k * spacing;

				int cid = getCID(ions, 2 * numIons, i, j, k);
				if (domainDecomp->procOwnsPos(x,y,z, domain)) {
					addMolecule(x, y, z, id, cid, particleContainer);
				}
				// increment id in any case, because this particle will probably
				// be added by some other process
				id++;
			}
		}

		percentageRead = i * percentage;
		_logger->info() << "Finished reading molecules: " << (percentageRead) << "%\r" << flush;
	}

	delete[] ions;

	removeMomentum(particleContainer, _components);
	domain->evaluateRho(particleContainer->getNumberOfParticles(), domainDecomp);
	_logger->info() << "Calculated Rho=" << domain->getglobalRho() << endl;
	inputTimer.stop();
	_logger->info() << "Initial IO took:                 " << inputTimer.get_etime() << " sec" << endl;
	return id;
}