void LayoutListMarker::updateMargins()
{
    const FontMetrics& fontMetrics = style()->fontMetrics();

    LayoutUnit marginStart = 0;
    LayoutUnit marginEnd = 0;

    if (isInside()) {
        if (isImage()) {
            marginEnd = cMarkerPaddingPx;
        } else {
            switch (listStyleCategory()) {
            case ListStyleCategory::Symbol:
                marginStart = -1;
                marginEnd = fontMetrics.ascent() - minPreferredLogicalWidth() + 1;
                break;
            default:
                break;
            }
        }
    } else {
        if (style()->isLeftToRightDirection()) {
            if (isImage()) {
                marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx;
            } else {
                int offset = fontMetrics.ascent() * 2 / 3;
                switch (listStyleCategory()) {
                case ListStyleCategory::None:
                    break;
                case ListStyleCategory::Symbol:
                    marginStart = -offset - cMarkerPaddingPx - 1;
                    break;
                default:
                    marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferredLogicalWidth();
                }
            }
            marginEnd = -marginStart - minPreferredLogicalWidth();
        } else {
            if (isImage()) {
                marginEnd = cMarkerPaddingPx;
            } else {
                int offset = fontMetrics.ascent() * 2 / 3;
                switch (listStyleCategory()) {
                case ListStyleCategory::None:
                    break;
                case ListStyleCategory::Symbol:
                    marginEnd = offset + cMarkerPaddingPx + 1 - minPreferredLogicalWidth();
                    break;
                default:
                    marginEnd = 0;
                }
            }
            marginStart = -marginEnd - minPreferredLogicalWidth();
        }

    }

    mutableStyleRef().setMarginStart(Length(marginStart, Fixed));
    mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed));
}
示例#2
0
void LayoutListMarker::updateContent() {
  // FIXME: This if-statement is just a performance optimization, but it's messy
  // to use the preferredLogicalWidths dirty bit for this.
  // It's unclear if this is a premature optimization.
  if (!preferredLogicalWidthsDirty())
    return;

  m_text = "";

  if (isImage())
    return;

  switch (getListStyleCategory()) {
    case ListStyleCategory::None:
      break;
    case ListStyleCategory::Symbol:
      m_text = ListMarkerText::text(style()->listStyleType(),
                                    0);  // value is ignored for these types
      break;
    case ListStyleCategory::Language:
      m_text =
          ListMarkerText::text(style()->listStyleType(), m_listItem->value());
      break;
  }
}
示例#3
0
void ImageThread::errorHandler(QUrl url, int err) {
    switch (err) {
    case 202:
    case 404:
        if (isImage(url)) {
            _blackList->add(url.toString());
            setCompleted(url.toString(), "");
        }
        else {
            // If there are still images in the list, wait until they finished (maybe they still exist)
            // else close immediately
            if (isDownloadFinished()) {
                stop();

                emit errorMessage("404 - Page not found");
                emit closeRequest(this, 404);
            }
            else {
                _closeWhenFinished = true;
            }
        }
        break;

    case 999:
        emit errorMessage("You are banned");
        break;

    default:
        QLOG_ERROR() << "ImageOverview :: Unhandled error (" << url.toString() << "," << err << ")";
        break;
    }
}
void LayoutListMarker::layout()
{
    ASSERT(needsLayout());
    LayoutAnalyzer::Scope analyzer(*this);

    if (isImage()) {
        updateMarginsAndContent();
        LayoutSize imageSize(imageBulletSize());
        setWidth(imageSize.width());
        setHeight(imageSize.height());
    } else {
        setLogicalWidth(minPreferredLogicalWidth());
        setLogicalHeight(style()->fontMetrics().height());
    }

    setMarginStart(0);
    setMarginEnd(0);

    Length startMargin = style()->marginStart();
    Length endMargin = style()->marginEnd();
    if (startMargin.isFixed())
        setMarginStart(startMargin.value());
    if (endMargin.isFixed())
        setMarginEnd(endMargin.value());

    clearNeedsLayout();
}
void LayoutListMarker::computePreferredLogicalWidths()
{
    ASSERT(preferredLogicalWidthsDirty());
    updateContent();

    if (isImage()) {
        LayoutSize imageSize(imageBulletSize());
        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHorizontalWritingMode() ? imageSize.width() : imageSize.height();
        clearPreferredLogicalWidthsDirty();
        updateMargins();
        return;
    }

    const Font& font = style()->font();

    LayoutUnit logicalWidth = 0;
    switch (listStyleCategory()) {
    case ListStyleCategory::None:
        break;
    case ListStyleCategory::Symbol:
        logicalWidth = (font.fontMetrics().ascent() * 2 / 3 + 1) / 2 + 2;
        break;
    case ListStyleCategory::Language:
        logicalWidth = getWidthOfTextWithSuffix();
        break;
    }

    m_minPreferredLogicalWidth = logicalWidth;
    m_maxPreferredLogicalWidth = logicalWidth;

    clearPreferredLogicalWidthsDirty();

    updateMargins();
}
int LayoutListMarker::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
{
    ASSERT(linePositionMode == PositionOnContainingLine);
    if (!isImage())
        return m_listItem->baselinePosition(baselineType, firstLine, direction, PositionOfInteriorLineBoxes);
    return LayoutBox::baselinePosition(baselineType, firstLine, direction, linePositionMode);
}
IntRect LayoutListMarker::getRelativeMarkerRect() const
{
    if (isImage()) {
        IntSize imageSize = flooredIntSize(imageBulletSize());
        return IntRect(0, 0, imageSize.width(), imageSize.height());
    }

    IntRect relativeRect;
    switch (listStyleCategory()) {
    case ListStyleCategory::None:
        return IntRect();
    case ListStyleCategory::Symbol: {
        // TODO(wkorman): Review and clean up/document the calculations below.
        // http://crbug.com/543193
        const FontMetrics& fontMetrics = style()->fontMetrics();
        int ascent = fontMetrics.ascent();
        int bulletWidth = (ascent * 2 / 3 + 1) / 2;
        relativeRect = IntRect(1, 3 * (ascent - ascent * 2 / 3) / 2, bulletWidth, bulletWidth);
        }
        break;
    case ListStyleCategory::Language:
        relativeRect = IntRect(0, 0, getWidthOfTextWithSuffix(), style()->font().fontMetrics().height());
        break;
    }

    if (!style()->isHorizontalWritingMode()) {
        relativeRect = relativeRect.transposedRect();
        relativeRect.setX(size().width() - relativeRect.x() - relativeRect.width());
    }

    return relativeRect;
}
示例#8
0
bool makeThumbnail(const QString & path,
                   ThumbnailType type)
{
    QFileInfo info(path);
    ContentThumbnail db(info.path());
    QImage thumbnail;
    if (!db.loadThumbnail(path, THUMBNAIL_LARGE, thumbnail))
    {
        // So far, only support image thumbnail in explorer.
        // The viewer can generate thumbnail themselves.
        if (!isImage(info.suffix()))
        {
            return false;
        }

        // Try to load it if it's a image.
        if (!thumbnail.load(path))
        {
            return false;
        }

        thumbnail = thumbnail.scaled(thumbnailSize(THUMBNAIL_LARGE), Qt::IgnoreAspectRatio);
        db.storeThumbnail(info.fileName(), THUMBNAIL_LARGE, thumbnail);

        // Return true even the thumbnail can not be stored.
        return true;
    }
    return true;

}
示例#9
0
void LayoutListMarker::layout() {
  ASSERT(needsLayout());
  LayoutAnalyzer::Scope analyzer(*this);

  if (isImage()) {
    updateMarginsAndContent();
    LayoutSize imageSize(imageBulletSize());
    setWidth(imageSize.width());
    setHeight(imageSize.height());
  } else {
    const SimpleFontData* fontData = style()->font().primaryFont();
    DCHECK(fontData);
    setLogicalWidth(minPreferredLogicalWidth());
    setLogicalHeight(
        LayoutUnit(fontData ? fontData->getFontMetrics().height() : 0));
  }

  setMarginStart(LayoutUnit());
  setMarginEnd(LayoutUnit());

  Length startMargin = style()->marginStart();
  Length endMargin = style()->marginEnd();
  if (startMargin.isFixed())
    setMarginStart(LayoutUnit(startMargin.value()));
  if (endMargin.isFixed())
    setMarginEnd(LayoutUnit(endMargin.value()));

  clearNeedsLayout();
}
示例#10
0
short RenderListMarker::baselinePosition(bool, bool) const
{
    if (!isImage()) {
        const Font& font = style()->font();
        return font.ascent() + (lineHeight(false) - font.height())/2;
    }
    return height();
}
示例#11
0
LayoutUnit LayoutListMarker::lineHeight(
    bool firstLine,
    LineDirectionMode direction,
    LinePositionMode linePositionMode) const {
  if (!isImage())
    return m_listItem->lineHeight(firstLine, direction,
                                  PositionOfInteriorLineBoxes);
  return LayoutBox::lineHeight(firstLine, direction, linePositionMode);
}
LayoutSize LayoutListMarker::imageBulletSize() const
{
    ASSERT(isImage());

    // FIXME: This is a somewhat arbitrary default width. Generated images for markers really won't
    // become particularly useful until we support the CSS3 marker pseudoclass to allow control over
    // the width and height of the marker box.
    LayoutUnit bulletWidth = style()->fontMetrics().ascent() / LayoutUnit(2);
    LayoutSize defaultBulletSize(bulletWidth, bulletWidth);
    return calculateImageIntrinsicDimensions(m_image.get(), defaultBulletSize, DoNotScaleByEffectiveZoom);
}
void LayoutListMarker::imageChanged(WrappedImagePtr o, const IntRect*)
{
    // A list marker can't have a background or border image, so no need to call the base class method.
    if (o != m_image->data())
        return;

    LayoutSize imageSize = isImage() ? imageBulletSize() : LayoutSize();
    if (size() != imageSize || m_image->errorOccurred())
        setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::ImageChanged);
    else
        setShouldDoFullPaintInvalidation();
}
示例#14
0
LayoutSize LayoutListMarker::imageBulletSize() const {
  ASSERT(isImage());
  const SimpleFontData* fontData = style()->font().primaryFont();
  DCHECK(fontData);
  if (!fontData)
    return LayoutSize();

  // FIXME: This is a somewhat arbitrary default width. Generated images for
  // markers really won't become particularly useful until we support the CSS3
  // marker pseudoclass to allow control over the width and height of the
  // marker box.
  LayoutUnit bulletWidth = fontData->getFontMetrics().ascent() / LayoutUnit(2);
  return m_image->imageSize(*this, style()->effectiveZoom(),
                            LayoutSize(bulletWidth, bulletWidth));
}
示例#15
0
IntRect RenderListMarker::getRelativeMarkerRect()
{
    if (isImage())
        return IntRect(m_x, m_y, m_image->imageSize().width(), m_image->imageSize().height());

    switch (style()->listStyleType()) {
        case DISC:
        case CIRCLE:
        case SQUARE: {
            // FIXME: Are these particular rounding rules necessary?
            const Font& font = style()->font();
            int ascent = font.ascent();
            int bulletWidth = (ascent * 2 / 3 + 1) / 2;
            return IntRect(m_x + 1, m_y + 3 * (ascent - ascent * 2 / 3) / 2, bulletWidth, bulletWidth);
        }
        case LNONE:
            return IntRect();
        case ARMENIAN:
        case CJK_IDEOGRAPHIC:
        case DECIMAL_LEADING_ZERO:
        case GEORGIAN:
        case HEBREW:
        case HIRAGANA:
        case HIRAGANA_IROHA:
        case KATAKANA:
        case KATAKANA_IROHA:
        case LDECIMAL:
        case LOWER_ALPHA:
        case LOWER_GREEK:
        case LOWER_LATIN:
        case LOWER_ROMAN:
        case UPPER_ALPHA:
        case UPPER_LATIN:
        case UPPER_ROMAN:
            if (m_text.isEmpty())
                return IntRect();
            const Font& font = style()->font();
            int itemWidth = font.width(m_text);
            const UChar periodSpace[2] = { '.', ' ' };
            int periodSpaceWidth = font.width(TextRun(periodSpace, 2));
            return IntRect(m_x, m_y + font.ascent(), itemWidth + periodSpaceWidth, font.height());
    }

    return IntRect();
}
示例#16
0
void LayoutListMarker::layout() {
  ASSERT(needsLayout());
  LayoutAnalyzer::Scope analyzer(*this);

  LayoutUnit blockOffset;
  for (LayoutBox* o = parentBox(); o && o != listItem(); o = o->parentBox()) {
    blockOffset += o->logicalTop();
  }
  if (listItem()->style()->isLeftToRightDirection()) {
    m_lineOffset = listItem()->logicalLeftOffsetForLine(
        blockOffset, DoNotIndentText, LayoutUnit());
  } else {
    m_lineOffset = listItem()->logicalRightOffsetForLine(
        blockOffset, DoNotIndentText, LayoutUnit());
  }
  if (isImage()) {
    updateMarginsAndContent();
    LayoutSize imageSize(imageBulletSize());
    setWidth(imageSize.width());
    setHeight(imageSize.height());
  } else {
    const SimpleFontData* fontData = style()->font().primaryFont();
    DCHECK(fontData);
    setLogicalWidth(minPreferredLogicalWidth());
    setLogicalHeight(
        LayoutUnit(fontData ? fontData->getFontMetrics().height() : 0));
  }

  setMarginStart(LayoutUnit());
  setMarginEnd(LayoutUnit());

  Length startMargin = style()->marginStart();
  Length endMargin = style()->marginEnd();
  if (startMargin.isFixed())
    setMarginStart(LayoutUnit(startMargin.value()));
  if (endMargin.isFixed())
    setMarginEnd(LayoutUnit(endMargin.value()));

  clearNeedsLayout();
}
示例#17
0
RenderImageResource* ImageLoader::renderImageResource()
{
    auto renderer = m_element->renderer();
    if (!renderer)
        return nullptr;

    // We don't return style generated image because it doesn't belong to the ImageLoader.
    // See <https://bugs.webkit.org/show_bug.cgi?id=42840>
    if (renderer->isImage() && !toRenderImage(*renderer).isGeneratedContent())
        return toRenderImage(*renderer).imageResource();

#if ENABLE(SVG)
    if (renderer->isSVGImage())
        return toRenderSVGImage(renderer)->imageResource();
#endif

#if ENABLE(VIDEO)
    if (renderer->isVideo())
        return toRenderVideo(*renderer).imageResource();
#endif

    return nullptr;
}
示例#18
0
QString SystemConfig::notesTemplate(int index)
{
    // Check SD at first.
    const QString NOTES_TEMPLATE = "notes_template";
    QDir dir(SDMMC_ROOT);
    if (!dir.cd(NOTES_TEMPLATE))
    {
        dir = QDir::home();
        if (!dir.cd(NOTES_TEMPLATE))
        {
            dir = QDir("/usr/share/");
            dir.cd(NOTES_TEMPLATE);
        }
    }

    QDir::Filters filters = QDir::Files|QDir::NoDotAndDotDot;
    QFileInfoList all = dir.entryInfoList(QStringList(), filters);
    if (index >= all.size() || index < 0)
    {
        index = 0;
    }

    while (index < all.size())
    {
        if (isImage(all.at(index).suffix()))
        {
            return all.at(index).absoluteFilePath();
        }
        ++index;
    }

    if (index >= all.size())
    {
        qWarning("Should not happen. %s", qPrintable(dir.path()));
    }
    return QString();
}
示例#19
0
void RenderListMarker::layout()
{
    ASSERT(needsLayout());
    ASSERT(!prefWidthsDirty());

    if (isImage()) {
        m_width = m_image->image()->width();
        m_height = m_image->image()->height();
    } else {
        m_width = minPrefWidth();
        m_height = style()->font().height();
    }

    m_marginLeft = m_marginRight = 0;

    Length leftMargin = style()->marginLeft();
    Length rightMargin = style()->marginRight();
    if (leftMargin.isFixed())
        m_marginLeft = leftMargin.value();
    if (rightMargin.isFixed())
        m_marginRight = rightMargin.value();

    setNeedsLayout(false);
}
示例#20
0
void RenderListMarker::calcPrefWidths()
{
    ASSERT(prefWidthsDirty());

    m_text = "";

    if (isImage()) {
        m_minPrefWidth = m_maxPrefWidth = m_image->image()->width();
        setPrefWidthsDirty(false);
        updateMargins();
        return;
    }

    const Font& font = style()->font();

    int width = 0;
    EListStyleType type = style()->listStyleType();
    switch (type) {
        case LNONE:
            break;
        case CIRCLE:
        case DISC:
        case SQUARE:
            m_text = listMarkerText(type, 0); // value is ignored for these types
            width = (font.ascent() * 2 / 3 + 1) / 2 + 2;
            break;
        case ARMENIAN:
        case CJK_IDEOGRAPHIC:
        case DECIMAL_LEADING_ZERO:
        case GEORGIAN:
        case HEBREW:
        case HIRAGANA:
        case HIRAGANA_IROHA:
        case KATAKANA:
        case KATAKANA_IROHA:
        case LDECIMAL:
        case LOWER_ALPHA:
        case LOWER_GREEK:
        case LOWER_LATIN:
        case LOWER_ROMAN:
        case UPPER_ALPHA:
        case UPPER_LATIN:
        case UPPER_ROMAN:
            m_text = listMarkerText(type, m_listItem->value());
            if (m_text.isEmpty())
                width = 0;
            else {
                int itemWidth = font.width(m_text);
                const UChar periodSpace[2] = { '.', ' ' };
                int periodSpaceWidth = font.width(TextRun(periodSpace, 2));
                width = itemWidth + periodSpaceWidth;
            }
            break;
    }

    m_minPrefWidth = width;
    m_maxPrefWidth = width;

    setPrefWidthsDirty(false);
    
    updateMargins();
}
示例#21
0
void RenderListMarker::updateMargins()
{
    const Font& font = style()->font();

    int marginLeft = 0;
    int marginRight = 0;

    if (isInside()) {
        if (isImage()) {
            if (style()->direction() == LTR)
                marginRight = cMarkerPadding;
            else
                marginLeft = cMarkerPadding;
        } else switch (style()->listStyleType()) {
            case DISC:
            case CIRCLE:
            case SQUARE:
                if (style()->direction() == LTR) {
                    marginLeft = -1;
                    marginRight = font.ascent() - minPrefWidth() + 1;
                } else {
                    marginLeft = font.ascent() - minPrefWidth() + 1;
                    marginRight = -1;
                }
                break;
            default:
                break;
        }
    } else {
        if (style()->direction() == LTR) {
            if (isImage())
                marginLeft = -minPrefWidth() - cMarkerPadding;
            else {
                int offset = font.ascent() * 2 / 3;
                switch (style()->listStyleType()) {
                    case DISC:
                    case CIRCLE:
                    case SQUARE:
                        marginLeft = -offset - cMarkerPadding - 1;
                        break;
                    case LNONE:
                        break;
                    default:
                        marginLeft = m_text.isEmpty() ? 0 : -minPrefWidth() - offset / 2;
                }
            }
        } else {
            if (isImage())
                marginLeft = cMarkerPadding;
            else {
                int offset = font.ascent() * 2 / 3;
                switch (style()->listStyleType()) {
                    case DISC:
                    case CIRCLE:
                    case SQUARE:
                        marginLeft = offset + cMarkerPadding + 1 - minPrefWidth();
                        break;
                    case LNONE:
                        break;
                    default:
                        marginLeft = m_text.isEmpty() ? 0 : offset / 2;
                }
            }
        }
        marginRight = -marginLeft - minPrefWidth();
    }

    style()->setMarginLeft(Length(marginLeft, Fixed));
    style()->setMarginRight(Length(marginRight, Fixed));
}
示例#22
0
short RenderListMarker::lineHeight(bool, bool) const
{
    if (!isImage())
        return m_listItem->lineHeight(false, true);
    return height();
}
示例#23
0
/*	getDiscType
*	method checks which kind of cd/dvd is to burn
*	returns integer which is defined in header (AI.h)
*/
int
ProjectTypeSelector::getDiscType()
{		
	if(objFileAccess == NULL)
		throw new ProjectTypeSelectorException(new BString("FileAccess object isn't seted ProjectTypeSelector::getDiscType()"));

	objFileAccess->generateFileInfos();
	TypeList = objFileAccess->getTypes();
	fSizeOfFiles = objFileAccess->getFileSize();
	FileList = objFileAccess->getFiles();
	
	if(FileList->CountItems() == 0) {
		return EMPTYLIST;
	}
	
	if(FileList->CountItems() == 1 && isVolume()) {
	
		//CD or DVD
		if(fSizeOfFiles > CDSIZE) {
			return DVDCOPY;
		}
		else {
			return CDCOPY;
		}
	}
	else if(FileList->CountItems() == 1 && isCue()) {
		return CUE;
	}
	else if(FileList->CountItems() == 1 && isImage()) {
		
		//CD or DVD
		if(fSizeOfFiles > CDSIZE) {
			return DVDIMAGE;
		}
		else {
			return CDIMAGE;
		}
	}
	else if(FileList->CountItems() == 1 && isProject()) {
		return PORJECT;
	}
	
	if(isAudioDisc() && intPlayTime > AUDIOCDPLAYTIME) {
		return AUDIODVD;
	}
	else if(isAudioDisc()) {
		return AUDIOCD;
	}
		
	//CD or DVD
	if(fSizeOfFiles > CDSIZE) {
		return DATADVD;
	}
	else {
		
		//Video CD or data CD
		if(isVideoDisc()) {
			return VCD;
		}
		else {
			return DATACD;
		}
	}
	
	return ERROR;
}
示例#24
0
void ProgXrayImport::getFlatfield(const FileName &fnFFinput,
                                  Image<double> &Iavg)
{

    // Process the flatfield images


    MultidimArray<double> &mdaIavg = Iavg();

    Matrix1D<double> expTimeArray, cBeamArray, slitWidthArray; // Local vectors

    DataSource ldSource = dSource;

    // Checking if fnFFinput is a single file to obtain the flatfield avg from
    if (extFlat && isImage(fnFFinput))
    {
        fMD.read(fnFFinput);
        ldSource = NONE;
    }
    else
    {
        switch (ldSource)
        {
        case MISTRAL:
            if (!H5File.checkDataset(fnFFinput.getBlockName().c_str()))
                break;
            {
                fMD.read(fnFFinput);
                H5File.getDataset("NXtomo/instrument/bright_field/ExpTimes", expTimeArray, false);
                H5File.getDataset("NXtomo/instrument/bright_field/current", cBeamArray, false);

                // If expTime is empty or only one single value in nexus file then we fill with 1
                if (expTimeArray.size() < 2)
                {
                    reportWarning("Input file does not contains flatfields' exposition time information.");
                    expTimeArray.initConstant(fMD.size(), 1.);
                }
                // If current is empty or only one single value in nexus file then we fill with 1
                if (cBeamArray.size() < 2)
                {
                    reportWarning("Input file does not contains flatfields' current beam information.");
                    cBeamArray.initConstant(fMD.size(), 1.);
                }

            }

            // Since Alba does not provide slit width, we set to ones
            slitWidthArray.initConstant(fMD.size(), 1.);

            break;
        case BESSY:
            {
                size_t objId;

                for (size_t i = fIni; i <= fEnd; ++i)
                {
                    objId = fMD.addObject();
                    fMD.setValue(MDL_IMAGE, fnFFinput + formatString("/img%d.spe", i), objId);
                }
                break;
            }
        case GENERIC:
            {
                // Get Darkfield
                std::cout << "Getting darkfield from "+fnFFinput << " ..." << std::endl;
                getDarkfield(fnFFinput, IavgDark);
                if (darkFix)
                    IavgDark.write(fnRoot+"_"+fnFFinput.removeDirectories()+"_darkfield.xmp");

                std::vector<FileName> listDir;
                fnFFinput.getFiles(listDir);
                size_t objId;

                for (size_t i = 0; i < listDir.size(); ++i)
                {
                    if (!listDir[i].hasImageExtension())
                        continue;
                    objId = fMD.addObject();
                    fMD.setValue(MDL_IMAGE, fnFFinput+"/"+listDir[i], objId);
                }
            }
            break;
        }
    }

    if ( fMD.size() == 0 )
    {
        reportWarning("XrayImport::getFlatfield: No images to process");
        return;
    }

    ImageInfo imFFInfo;

    getImageInfo(fMD, imFFInfo);

    if ( (imFFInfo.adim.xdim != imgInfo.adim.xdim) || (imFFInfo.adim.ydim != imgInfo.adim.ydim) )
    {
        reportWarning(formatString("XrayImport:: Flatfield images size %dx%d different from Tomogram images size %dx%d",
                                   imFFInfo.adim.xdim,imFFInfo.adim.ydim,imgInfo.adim.xdim,imgInfo.adim.ydim));
        std::cout << "Setting crop values to fit the smallest dimensions." <<std::endl;

        // This shift in the crop sizes is exclusive of Mistral data
        cropSizeXi = (imgInfo.adim.xdim - std::min(imgInfo.adim.xdim-cropSizeX*2, imFFInfo.adim.xdim))/2 + 1;
        cropSizeYi = (imgInfo.adim.ydim - std::min(imgInfo.adim.ydim-cropSizeY*2, imFFInfo.adim.ydim))/2 + 1;
        cropSizeXe = cropSizeXi - 2;
        cropSizeYe = cropSizeYi - 2;
    }

    int cropX = (imFFInfo.adim.xdim - (imgInfo.adim.xdim-cropSizeXi-cropSizeXe))/2;// - 1;
    int cropY = (imFFInfo.adim.ydim - (imgInfo.adim.ydim-cropSizeYi-cropSizeYe))/2;// - 1;


    int N  = 0;
    Image<double> Iaux;
    FileName fnImg;

    FOR_ALL_OBJECTS_IN_METADATA(fMD)
    {
        fMD.getValue(MDL_IMAGE, fnImg, __iter.objId);

        readAndCrop(fnImg, Iaux, cropX, cropY);


        if ( darkFix )
        {
            Iaux() -= IavgDark();
            forcePositive(Iaux());
        }

        double currentBeam = 1;
        double expTime = 1;
        double slitWidth = 1;

        switch (ldSource)
        {
        case MISTRAL:
            {
                size_t idx = fnImg.getPrefixNumber();
                currentBeam = dMi(cBeamArray, idx-1);
                expTime = dMi(expTimeArray, idx-1);
                slitWidth = dMi(slitWidthArray, idx-1);
            }
            break;
        case BESSY:
        case GENERIC:
            readCorrectionInfo(fnImg, currentBeam, expTime, slitWidth);
            break;
        default:
            break;
        }

        Iaux() *= 1.0/(currentBeam*expTime*slitWidth);

        if ( N == 0 )
            mdaIavg = Iaux();
        else
            mdaIavg += Iaux();
        N++;
    }

    darkFix = false; // We reset just in case there is no dark field for tomo images

    mdaIavg*=1.0/N;

    /* Create a mask with zero valued pixels to apply boundaries median filter
     * to avoid dividing by zero when normalizing */

    MultidimArray<char> &mdaMask = MULTIDIM_ARRAY(bpMask);

    if ( !fnBPMask.empty() && !mdaIavg.sameShape(mdaMask) )
        REPORT_ERROR(ERR_MULTIDIM_SIZE, "XrayImport: Mask size does not match flat fields size.");

    if (BPFactor > 0)
    {
        double  avg, std;
        mdaIavg.computeAvgStdev(avg, std);
        mdaMask.resize(mdaIavg, false);

        double th = avg - std*BPFactor;
        FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(mdaMask)
        dAi(mdaMask, n) = dAi(mdaIavg, n) < th;
    }
    else if (fnBPMask.empty())
        mdaIavg.equal(0,mdaMask);

    MultidimArray<char> mask = mdaMask;
    boundMedianFilter(mdaIavg,mask);
}
示例#25
0
void LayoutListMarker::updateMargins() {
  const SimpleFontData* fontData = style()->font().primaryFont();
  DCHECK(fontData);
  if (!fontData)
    return;
  const FontMetrics& fontMetrics = fontData->getFontMetrics();

  LayoutUnit marginStart;
  LayoutUnit marginEnd;

  if (isInside()) {
    if (isImage()) {
      marginEnd = LayoutUnit(cMarkerPaddingPx);
    } else {
      switch (getListStyleCategory()) {
        case ListStyleCategory::Symbol:
          marginStart = LayoutUnit(-1);
          marginEnd =
              fontMetrics.ascent() - minPreferredLogicalWidth() + 1 +
              LayoutUnit(cUAMarkerMarginEm * style()->computedFontSize());
          break;
        default:
          break;
      }
    }
  } else {
    if (style()->isLeftToRightDirection()) {
      if (isImage()) {
        marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx;
      } else {
        int offset = fontMetrics.ascent() * 2 / 3;
        switch (getListStyleCategory()) {
          case ListStyleCategory::None:
            break;
          case ListStyleCategory::Symbol:
            marginStart = LayoutUnit(-offset - cMarkerPaddingPx - 1);
            break;
          default:
            marginStart =
                m_text.isEmpty() ? LayoutUnit() : -minPreferredLogicalWidth();
        }
      }
      marginEnd = -marginStart - minPreferredLogicalWidth();
    } else {
      if (isImage()) {
        marginEnd = LayoutUnit(cMarkerPaddingPx);
      } else {
        int offset = fontMetrics.ascent() * 2 / 3;
        switch (getListStyleCategory()) {
          case ListStyleCategory::None:
            break;
          case ListStyleCategory::Symbol:
            marginEnd =
                offset + cMarkerPaddingPx + 1 - minPreferredLogicalWidth();
            break;
          default:
            marginEnd = LayoutUnit();
        }
      }
      marginStart = -marginEnd - minPreferredLogicalWidth();
    }
  }

  mutableStyleRef().setMarginStart(Length(marginStart, Fixed));
  mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed));
}
示例#26
0
void NewsSite::parseRSS(QDomDocument domDoc)
{
    QMutexLocker locker(&m_lock);

    QDomNode channelNode = domDoc.documentElement().namedItem("channel");

    m_desc = channelNode.namedItem("description")
        .toElement().text().simplified();

    QDomNode imageNode = channelNode.namedItem("image");
    if (!imageNode.isNull())
        m_imageURL = imageNode.namedItem("url").toElement().text().simplified();

    QDomNodeList items = domDoc.elementsByTagName("item");

    for (unsigned int i = 0; i < (unsigned) items.count(); i++)
    {
        QDomNode itemNode = items.item(i);
        QString title = ReplaceHtmlChar(itemNode.namedItem("title")
                                        .toElement().text().simplified());

        QDomNode descNode = itemNode.namedItem("description");
        QString description = QString::null;
        if (!descNode.isNull())
        {
            description = descNode.toElement().text().simplified();
            description = ReplaceHtmlChar(description);
        }

        QDomNode linkNode = itemNode.namedItem("link");
        QString url = QString::null;
        if (!linkNode.isNull())
            url = linkNode.toElement().text().simplified();

        QDomNode enclosureNode = itemNode.namedItem("enclosure");
        QString enclosure = QString::null;
        QString enclosure_type = QString::null;
        QString thumbnail = QString::null;
        if (!enclosureNode.isNull())
        {
            QDomAttr enclosureURL = enclosureNode.toElement()
                .attributeNode("url");

            if (!enclosureURL.isNull())
                enclosure  = enclosureURL.value();

            QDomAttr enclosureType = enclosureNode.toElement()
                .attributeNode("type");
            if (!enclosureType.isNull()) 
            {
                enclosure_type  = enclosureType.value();

                if (enclosure_type == "image/jpeg")
                {
                    thumbnail = enclosure;
                    enclosure = QString::null;
                }

                // fix for broken feeds that don't add the enclosure type
                if (enclosure_type == "" || enclosure_type.isNull())
                {
                    QStringList imageExtensions = QStringList() << ".jpg" << ".jpeg" << ".png" << ".gif";
                    for (int x = 0; x < imageExtensions.count(); x++)
                    {
                        if (enclosure.toLower().endsWith(imageExtensions[x]))
                        {
                            thumbnail = enclosure;
                            enclosure = QString::null;
                            break;
                        }
                    }
                }
            }
        }

        //////////////////////////////////////////////////////////////
        // From this point forward, we process RSS 2.0 media tags.
        // Please put all other tag processing before this comment.
        // See http://www.rssboard.org/media-rss for details
        //////////////////////////////////////////////////////////////

        // Some media: tags can be enclosed in a media:group item.
        // If this item is present, use it to find the media tags,
        // otherwise, proceed.
        QDomNode mediaGroup = itemNode.namedItem("media:group");
        if (!mediaGroup.isNull())
            itemNode = mediaGroup;

        QDomNode thumbNode = itemNode.namedItem("media:thumbnail");
        if (!thumbNode.isNull())
        {
            QDomAttr thumburl = thumbNode.toElement().attributeNode("url");
            if (!thumburl.isNull())
                thumbnail = thumburl.value();
        }

        QDomNode playerNode = itemNode.namedItem("media:player");
        QString mediaurl = QString::null;
        if (!playerNode.isNull())
        {
            QDomAttr mediaURL = playerNode.toElement().attributeNode("url");
            if (!mediaURL.isNull())
                mediaurl = mediaURL.value();
        }

        // If present, the media:description superscedes the RSS description
        descNode = itemNode.namedItem("media:description");
        if (!descNode.isNull())
            description = descNode.toElement().text().simplified();

        // parse any media:content items looking for any images or videos
        QDomElement e = itemNode.toElement();
        QDomNodeList mediaNodes = e.elementsByTagName("media:content");
        for (int x = 0; x < mediaNodes.count(); x++)
        {
            QString medium;
            QString type;
            QString url;

            QDomElement mediaElement = mediaNodes.at(x).toElement();

            if (mediaElement.isNull())
                continue;

            if (mediaElement.hasAttribute("medium"))
                medium = mediaElement.attributeNode("medium").value();

            if (mediaElement.hasAttribute("type"))
                type = mediaElement.attributeNode("type").value();

            if (mediaElement.hasAttribute("url"))
                url = mediaElement.attributeNode("url").value();

            LOG(VB_GENERAL, LOG_DEBUG,
                QString("parseRSS found media:content: medium: %1, type: %2, url: %3")
                        .arg(medium).arg(type).arg(url));

            // if this is an image use it as the thumbnail if we haven't found one yet
            if (thumbnail.isEmpty() && (medium == "image" || isImage(type)))
                thumbnail = url;

            // if this is a video use it as the enclosure if we haven't found one yet
            if (enclosure.isEmpty() && (medium == "video" || isVideo(type)))
                enclosure = url;
        }

        insertNewsArticle(NewsArticle(title, description, url,
                                      thumbnail, mediaurl, enclosure));
    }
}
示例#27
0
//
// imgResize(()
//
BOOL imgResize(IMG_RESIZE * psImgResize)
{
	CHAR *lpMess="";
	INT fTrack=FALSE;
	INT iErr;
	EN_FILE_TYPE enImageType=0;
    IMGHEADER ImgHead;
	POINT ptArea;
	POINT ptPhoto;
	RECT srRectSource,srRectLogo;

	SIZE sDest; // Dimensione destinazione
	RECT rDest; // Rettangolo destinazione

	INT		hdlImage;
	INT		hdlImageNew;
	INT		hdlImageEnd;
	SIZE	sPhotoDest;
	DWORD	dw;
	BOOL	bFillBack;

	if (!psImgResize->pszFileSource) return TRUE;

	// 
	// Controllo se esiste il file
	//
	if (!fileCheck(psImgResize->pszFileSource)) 
	{
		printf("Il file %s non esiste",psImgResize->pszFileSource);
		ehLogWrite("Il file %s non esiste",psImgResize->pszFileSource);
		return TRUE;
	}

	// 
	// Controllo LogoFile
	//
	if (*psImgResize->sLogo.szFile)
	{
		if (!fileCheck(psImgResize->sLogo.szFile)) 
		{
			printf("Il logofile %s non esiste",psImgResize->sLogo.szFile);
			ehLogWrite("Il logofile %s non esiste",psImgResize->sLogo.szFile);
			return TRUE;
		}
	}

//	remove(szNewFile);

	// ------------------------------------------------------------------------
	// A) Leggere le dimensioni del sorgente
	//
	
	enImageType=IMG_UNKNOW;
	switch (isImage(psImgResize->pszFileSource))
	{
		case IMG_JPEG:
			if (JPGReadHeader(psImgResize->pszFileSource,&ImgHead,JME_HIDE)) enImageType=IMG_JPEG;
			break;

		case IMG_GIF:
			if (GIFReadHeader(psImgResize->pszFileSource,&ImgHead,JME_HIDE)) enImageType=IMG_GIF;
			break;

		case IMG_PNG:
			if (PNGReadHeader(psImgResize->pszFileSource,&ImgHead,JME_HIDE)) enImageType=IMG_PNG;
			break;
		
		default:
			break;
	}

	if (!enImageType)
	{
//		printf("ko");
		printf("%s: errore in lettura Header",psImgResize->pszFileSource);
		ehLogWrite("%s: errore in lettura Header",psImgResize->pszFileSource);
		return TRUE;
	}
	

	sPhotoDest.cx=(INT) (psImgResize->sFix.cx*psImgResize->sPhoto.dPerc/100);
	sPhotoDest.cy=(INT) (psImgResize->sFix.cy*psImgResize->sPhoto.dPerc/100);

	// 
	// B) Calcolare le nuove dimensioni
	//
	IMGCalcSize(&ImgHead,		// Dimensioni del sorgente
				&sPhotoDest,	// Area disponibile
				psImgResize->psMin,
				psImgResize->psMax,
				psImgResize->enPhotoAdatta,  // Tipo di adattamento
				psImgResize->sPhoto.iAlignHor,	   // Allineamento orizzontale
				psImgResize->sPhoto.iAlignVer,	   // Allineamento verticale
				&sDest,		   // Dimensioni della destinazione
				&rDest,
				&srRectSource); 	   // Posizionamento in destinazione
	if (!sPhotoDest.cy||!sPhotoDest.cx) 
		memcpy(&sPhotoDest,&sDest,sizeof(sDest));

	memcpy(&psImgResize->sDest,&sDest,sizeof(sDest));
	//
	// C) Carica il sorgente in memoria
	//
	switch (ImgHead.enType)
	{
		BOOL bError=false;
		
		case IMG_JPEG:

			//
			// Lettura veloce
			//
			if (psImgResize->bQuickLoading) {

				INT iPerc,iFactor;
				SIZE sizSource,sAp1;
				RECT sAp2;
				sizSource.cx=ImgHead.bmiHeader.biWidth;
				sizSource.cy=ImgHead.bmiHeader.biHeight;
				iFactor=JPGGetFactor(&sizSource,&sPhotoDest,&iPerc);
				bError=!JPGReadFileEx(psImgResize->pszFileSource,&hdlImage,NULL,iFactor,JDCT_IFAST,NULL,FALSE,IMG_PIXEL_RGB);
				if (!bError) {
						
					// Letto + piccolo, calcolo nuove dimensioni
					IMGHEADER * psImgHead;
					//printf("[%d:%d]" CRLF,bError,hdlImage);
					if (hdlImage>-1) {
						psImgHead=(IMGHEADER *) memoLock(hdlImage);
						IMGCalcSize(psImgHead,      // Dimensioni del sorgente
									&sPhotoDest,	   // Area disponibile
									psImgResize->psMin,
									psImgResize->psMax,
									psImgResize->enPhotoAdatta,  // Tipo di adattamento
									psImgResize->sPhoto.iAlignHor,	   // Allineamento orizzontale
									psImgResize->sPhoto.iAlignVer,	   // Allineamento verticale
									&sAp1,		   // Dimensioni della destinazione
									&sAp2,
									&srRectSource); 	   // Posizionamento in destinazione				
									}
						memoUnlockEx(hdlImage,"a1");
					} else bError=TRUE;
			}
			//
			// Lettura dell'intera immagine
			//
			else {
				bError=!JPGReadFile(psImgResize->pszFileSource,&hdlImage,NULL,NULL,FALSE,IMG_PIXEL_RGB);
			}

			if (bError)
			{
#ifdef EH_CONSOLE
				printf("ko:[%s] errore in lettura JPG",psImgResize->pszFileSource);
#endif
				ehLogWrite("%s: errore in lettura JPG",psImgResize->pszFileSource);
				return TRUE;
			}
			//hdlImage=IMGToRGB(hdlImage,1);
			break;

		case IMG_GIF:
			if (!GIFReadFile(psImgResize->pszFileSource,&hdlImage,psImgResize->cBackColor,FALSE,IMG_PIXEL_RGB)) 
			{
				printf("ko");
				printf("%s: errore in lettura GIF",psImgResize->pszFileSource);
				ehLogWrite("%s: errore in lettura GIF",psImgResize->pszFileSource);
				printf("Errore"); //getch();
				return TRUE;
			}
			break;

		case IMG_PNG:
			if (!PNGReadFile(psImgResize->pszFileSource,&hdlImage,NULL,FALSE)) 
			{
				printf("ko");
				printf("%s: errore in lettura PNG",psImgResize->pszFileSource);
				ehLogWrite("%s: errore in lettura PNG",psImgResize->pszFileSource);
				printf("Errore"); //getch();
				return TRUE;
			}
			break;

		default:
			printf("ko");
			printf("%s: formato non gestito",psImgResize->pszFileSource);
			ehLogWrite("%s: formato non gestito",psImgResize->pszFileSource);
			return TRUE;
	}

	// 
	// D) Ridimensionarlo
	//

	if (sDest.cy<16) 
		hdlImageNew=IMGRemaker(	hdlImage,
								&srRectSource,
								sDest.cx,
								sDest.cy,
								TRUE,
								psImgResize->iResampling);
		else
		hdlImageNew=IMGResampling(	hdlImage,
									&srRectSource,
									sDest.cx,
									sDest.cy,
									psImgResize->iResampling);
	if (hdlImageNew<0)
	{
#ifdef EH_CONSOLE
		printf("ko:%s: errore in IMGRemaker() %d",psImgResize->pszFileSource,hdlImageNew);
#endif
		ehLogWrite("%s: errore in IMGRemaker() %d",psImgResize->pszFileSource,hdlImageNew);
		memoFree(hdlImage,"Img1"); // Libero memoria immagine
		hdlImage=-1;
		return TRUE;
	}

	//
	// DX) Eseguo (eventuali) rotazioni/mirror dell'immagine 
	//
	if (psImgResize->iOrientation>1) {

		INT hdlImage;
		
		switch (psImgResize->iOrientation) {
		
			case 2: // "flip horizontal",  // left right reversed mirror
				IMGMirrorX(hdlImageNew);
				break;

			case 3: // Rotate 180
				hdlImage=IMGRotation(ROT_180,hdlImageNew);
				memoFree(hdlImageNew,"rot");
				hdlImageNew=hdlImage;
				break;

			case 4: // upside down mirror
				IMGMirrorY(hdlImageNew);
				break;

			case 5: // Flipped about top-left <--> bottom-right axis.
			case 7: // flipped about top-right <--> bottom-left axis
				IMGMirrorX(hdlImageNew);
				IMGMirrorY(hdlImageNew);
				break;

			case 6: // rotate 90 cw to right it.
				hdlImage=IMGRotation(ROT_270,hdlImageNew);
				dw=sPhotoDest.cx; sPhotoDest.cx=sPhotoDest.cy; sPhotoDest.cy=dw;
				memoFree(hdlImageNew,"rot");
				hdlImageNew=hdlImage;
				break;

			case 8: // rotate 270 to right it.
				hdlImage=IMGRotation(ROT_90,hdlImageNew);
				dw=sPhotoDest.cx; sPhotoDest.cx=sPhotoDest.cy; sPhotoDest.cy=dw;
				memoFree(hdlImageNew,"rot");
				hdlImageNew=hdlImage;
				break;
				
		}
	}

	// ------------------------------------------------------------------------
	// E) Creare un'immagine con il colore di background scelto	 
	//	  2012 release: se trasparente rimane tale
	//
	bFillBack=true;
	if (ImgHead.enPixelType!=IMG_PIXEL_RGB_ALPHA) {

		if (psImgResize->enPhotoAdatta!=IMGPT_MAX_SIDE) 
			hdlImageEnd=IMGCreate(IMG_PIXEL_RGB,"newImage",sPhotoDest.cx,sPhotoDest.cy,NULL,FALSE);
			else
			{hdlImageEnd=IMGCreate(IMG_PIXEL_RGB,"newImage",sDest.cx,sDest.cy,NULL,FALSE); bFillBack=false;}

	} else {

		if (psImgResize->enPhotoAdatta!=IMGPT_MAX_SIDE) 
			hdlImageEnd=IMGCreate(IMG_PIXEL_RGB_ALPHA,"newImage",sPhotoDest.cx,sPhotoDest.cy,NULL,FALSE);
			else
			{hdlImageEnd=IMGCreate(IMG_PIXEL_RGB_ALPHA,"newImage",sDest.cx,sDest.cy,NULL,FALSE); }
	
	}
	
	if (bFillBack) IMGFill(hdlImageEnd,psImgResize->cBackColor);

	// ------------------------------------------------------------------------
	// E2) Applico gli autolivelli se richiesto
	//

	if (psImgResize->bAutoLevel)
	{
		if (ImgHead.iChannels==3) 
		{	
			hdlImageNew=IMGAutoLevel(hdlImageNew);
		}
	}

	//
	//	Ricalcolo il posizionamento
	//
	if (psImgResize->enPhotoAdatta!=IMGPT_MAX_SIDE) {

		if (psImgResize->enPhotoAdatta) {

			RectCalcSize(	&sDest,		// Dimensioni del sorgente
							&psImgResize->sFix,			// Dimensione Area destinazione finale
							psImgResize->psMin,			// Dimensione Area destinazione finale
							psImgResize->psMax,			// Dimensione Area destinazione finale
							IMGPT_NO, // Tipo di adattamento
							psImgResize->sPhoto.iAlignHor,		// Allineamento orizzontale
							psImgResize->sPhoto.iAlignVer,		// Allineamento verticale
							&psImgResize->sDest,		// Dimensioni della destinazione
							&rDest,
							NULL); 		// Posizionamento in destinazione
			memcpy(&sDest,&psImgResize->sDest,sizeof(SIZE));

		 } else _(rDest);

		// ------------------------------------------------------------------------
		// F) Inserire il sorgente nella destinazione
		//
		ptPhoto.x=rDest.left+psImgResize->sPhoto.iOffsetX;
		ptPhoto.y=rDest.top+psImgResize->sPhoto.iOffsetY;

	} else {ptPhoto.x=0; ptPhoto.y=0;}

	IMGCopy(hdlImageEnd, // --> La destinazione
			hdlImageNew, // <-- Il sorgente
			ptPhoto,		 // La posizione
			psImgResize->sPhoto.iAlpha);
	
	memoFree(hdlImageNew,"Img1");
	memoFree(hdlImage,"Img1"); // Libero memoria immagine
	hdlImage=-1;

	// 
	// G2) PAINT - Ping moltiplicato -------------------------------------------------------------
	//
	if (!strEmpty(psImgResize->sPaint.szFile))
	{
		INT iErr;
		INT hdlLogo=-1,hdlLogoNew=-1;
		IMGHEADER ImgLogoHead;
		SIZE sLogoDest;
		RECT rLogoDest;
//		BOOL bOffset;
		
		// a) Carico il PNG in memoria
		if (!PNGReadFile(psImgResize->sPaint.szFile,&hdlLogo,&iErr,FALSE))
		{
			printf("ko");
			printf("%s: errore in PNGReadFile() %d",psImgResize->sPaint.szFile,iErr);
			ehLogWrite("%s: errore in PNGReadFile() %d",psImgResize->sPaint.szFile,iErr);
			memoFree(hdlImageEnd,"Img2");
			return TRUE;
		}

		memcpy(&ImgLogoHead,memoLock(hdlLogo),sizeof(IMGHEADER));
		memoUnlockEx(hdlLogo,"A3");

		if (psImgResize->sPaint.psSizeFix) {

			memcpy(&sLogoDest,psImgResize->sLogo.psSizeFix,sizeof(SIZE));

		} else {
			sLogoDest.cx=(INT) (ImgLogoHead.bmiHeader.biWidth*psImgResize->sPaint.dPerc/100);
			sLogoDest.cy=(INT) (ImgLogoHead.bmiHeader.biHeight*psImgResize->sPaint.dPerc/100);
		}

		// b) Calcolo le nuove dimensioni
		IMGCalcSize(&ImgLogoHead,      // Dimensioni del sorgente
					&sLogoDest,		   // Area disponibile
					psImgResize->psMin,
					psImgResize->psMax,
					IMGPT_AL_FORMATO,  // Tipo di adattamento
					0,	   // Allineamento orizzontale
					0,	   // Allineamento verticale
					&sLogoDest,		   // Dimensioni della destinazione
					&rLogoDest,
					&srRectLogo); 	   // Posizionamento in destinazione

		
		// c) Creo (ridimensionando) il nuovo Ping
		hdlLogoNew=IMGResampling(hdlLogo,NULL,sLogoDest.cx,sLogoDest.cy,psImgResize->iResampling);
		memoFree(hdlLogo,"Img1"); // Libero memoria immagine
		hdlLogo=-1;

		if (hdlLogoNew<0)
		{
			printf("ko");
			printf("%s: errore in IMGRemaker(LOGO) %d",psImgResize->sPaint.szFile,hdlLogoNew);
			ehLogWrite("%s: errore in IMGRemaker(LOGO) %d",psImgResize->sPaint.szFile,hdlLogoNew);
			memoFree(hdlImageEnd,"Img2");
			return TRUE;
		}
	
		// Applico
		for (ptArea.y=(psImgResize->sPaint.iOffsetY-sLogoDest.cy);ptArea.y<psImgResize->sDest.cy;ptArea.y+=sLogoDest.cy)
		{
			INT iOffset=psImgResize->sPaint.iOffsetX-sLogoDest.cx;

			for (ptArea.x=iOffset;ptArea.x<psImgResize->sDest.cx;ptArea.x+=sLogoDest.cx)
			{
				POINT ptArea2;
				// printf("Copio: %d,%d (%d)",pArea.x,pArea.y,iLogoAlpha);
				IMGCopy(hdlImageEnd,	// La destinazione
						hdlLogoNew,		// Il sorgente
						ptArea,			// La posizione
						psImgResize->sPaint.iAlpha);

				if (psImgResize->iEchoPaint)
				{
					ptArea2.x=ptArea.x+sLogoDest.cx/4;
					ptArea2.y=ptArea.y+sLogoDest.cy/4;
					IMGCopy(hdlImageEnd,	// La destinazione
							hdlLogoNew,		// Il sorgente
							ptArea2,			// La posizione
							psImgResize->sPaint.iAlpha+psImgResize->iEchoPaint);
				}
			}
		}



		// e) Libero le risorse impegnate
		memoFree(hdlLogoNew,"Logo1"); // Libero memoria immagine
	}


	// 
	// G) Fonde il Ping (se presente)
	//
	if (!strEmpty(psImgResize->sLogo.szFile))
	{
		INT iErr;
		INT hdlLogo=-1,hdlLogoResized=-1;
		IMGHEADER sImgLogoHead;
		SIZE sLogoDest;
		RECT rLogoDest;
		
		if (!PNGReadFile(psImgResize->sLogo.szFile,&hdlLogo,&iErr,FALSE))
		{
			printf("ko: %s: errore in PNGReadFile() %d",psImgResize->sLogo.szFile,iErr);
			ehLogWrite("%s: errore in PNGReadFile() %d",psImgResize->sLogo.szFile,iErr);
			memoFree(hdlImageEnd,"Img2");
			return true;
		}

		memcpy(&sImgLogoHead,memoLock(hdlLogo),sizeof(IMGHEADER));
		memoUnlockEx(hdlLogo,"A4");

		if (psImgResize->sLogo.psSizeFix) {
			
			memcpy(&sLogoDest,psImgResize->sLogo.psSizeFix,sizeof(SIZE));
		
		} else {

			if (psImgResize->sLogo.dPerc<1) psImgResize->sLogo.dPerc=100;
			if (psImgResize->sLogo.bPosWhere) // Posiziono con riferimento alla foto
			{
				sLogoDest.cx=(INT) (sDest.cx*psImgResize->sLogo.dPerc/100);
				sLogoDest.cy=(INT) (sDest.cy*psImgResize->sLogo.dPerc/100);
			
			}
			else {
				sLogoDest.cx=(INT) (psImgResize->sDest.cx*psImgResize->sLogo.dPerc/100);
				sLogoDest.cy=(INT) (psImgResize->sDest.cy*psImgResize->sLogo.dPerc/100);
			}
		}
		
		//
		// Se serve ridimensiono il logo
		//
		if (sImgLogoHead.bmiHeader.biWidth!=sLogoDest.cx||
			sImgLogoHead.bmiHeader.biHeight!=sLogoDest.cy) {

				// b) Calcolo le nuove dimensioni
				IMGCalcSize(&sImgLogoHead,      // Dimensioni del sorgente
							&sLogoDest,		   // Area disponibile
							NULL,
							NULL,
							IMGPT_AL_FORMATO,  // Tipo di adattamento
							0,	   // Allineamento orizzontale
							0,	   // Allineamento verticale
							&sLogoDest,		   // Dimensioni della destinazione
							&rLogoDest,
							&srRectLogo); 	   // Posizionamento in destinazione

				// c) Creo (ridimensionando) il nuovo Ping
				
				if (sLogoDest.cy<16) 
					hdlLogoResized=IMGRemaker(hdlLogo,NULL,sLogoDest.cx,sLogoDest.cy,TRUE,psImgResize->iResampling);
					else
					hdlLogoResized=IMGResampling(hdlLogo,NULL,sLogoDest.cx,sLogoDest.cy,psImgResize->iResampling);

				memoFree(hdlLogo,"Img1"); // Libero memoria immagine
				hdlLogo=-1;
		} else {

			hdlLogoResized=hdlLogo;
			hdlLogo=-1;
		
		}

		if (hdlLogoResized<0)
		{
			printf("ko");
			printf("%s: errore in IMGRemaker(LOGO) %d",psImgResize->sLogo.szFile,hdlLogoResized);
			ehLogWrite("%s: errore in IMGRemaker(LOGO) %d",psImgResize->sLogo.szFile,hdlLogoResized);
			memoFree(hdlImageEnd,"Img2");
			return TRUE;
		}
	

		// 
		// Allineamento Orizzontale
		//
		switch (psImgResize->sLogo.iAlignHor)
		{
			case 1: // Left
				if (psImgResize->sLogo.bPosWhere) ptArea.x=rDest.left; else ptArea.x=0; 
				break;

			case 2: // Right
				if (psImgResize->sLogo.bPosWhere) 
						ptArea.x=rDest.right-sLogoDest.cx;
						else
						ptArea.x=psImgResize->sDest.cx-sLogoDest.cx;
				break;

			default:
			case 0: // Centra (Default)
//				pArea.x=((psImgResize->sDim.cx-sLogoDest.cx)/2);
				ptArea.x=rDest.left+((sDest.cx-sLogoDest.cx)/2);
				break;
		}

		// 
		// Allinamento Verticale
		//
		switch (psImgResize->sLogo.iAlignVer)
		{
			case 1: // Top
				if (psImgResize->sLogo.bPosWhere) ptArea.y=rDest.top; else ptArea.y=0;
				break;

			case 2: // Bottom
				if (psImgResize->sLogo.bPosWhere) ptArea.y=rDest.bottom-sLogoDest.cy; else ptArea.y=sPhotoDest.cy-sLogoDest.cy; // C'era un +1 cazzo
				break;

			default:
			case 0: // Centra (Default)
//				pArea.y=((psImgResize->sDim.cy-sLogoDest.cy)/2);
				ptArea.y=rDest.top+((sDest.cy-sLogoDest.cy)/2);
				break;
		}
		
		ptArea.x+=psImgResize->sLogo.iOffsetX;//iLogoOffsetX;
		ptArea.y+=psImgResize->sLogo.iOffsetY;//iLogoOffsetY;

		// printf("Copio: %d,%d (%d)",pArea.x,pArea.y,iLogoAlpha);
		IMGCopy(hdlImageEnd, // La destinazione
				hdlLogoResized, // Il sorgente
				ptArea,		 // La posizione
				psImgResize->sLogo.iAlpha); //(double) 100);//psImgResize->sLogo.iAlpha);  <-- da controllare il valore dell' alpha

//		if (strstr(psImgResize->pszFileDest,"\\big"))
//			printf("qui");

		// e) Libero le risorse impegnate
		memoFree(hdlLogoResized,"Logo1"); // Libero memoria immagine
	}


	//
	// Se ho dei comandi di testo li processo
	//
	if (!strEmpty(psImgResize->lpText)) TextProcessor(hdlImageEnd,psImgResize->lpText);


	// ------------------------------------------------------------------------
	// H) Salvare l'immagine
	//
	if (!psImgResize->enImageTypeSave) psImgResize->enImageTypeSave=IMG_JPEG; // Per compatibilità con il passato
	switch (psImgResize->enImageTypeSave)
	{
		case IMG_PNG:
			iErr=PNGSaveFile(psImgResize->pszFileDest,hdlImageEnd,psImgResize->iQuality);
			break;

		case IMG_JPEG:
			iErr=JPGSaveFile(psImgResize->pszFileDest,hdlImageEnd,psImgResize->iQuality);
			break;
		
		default:
			ehError();
			break;

	}

	memoFree(hdlImageEnd,"Img2");
	if (!iErr)
	{
#ifdef EH_CONSOLE
		printf("ko:%s: errore in JPGSave() %d",psImgResize->pszFileDest,iErr);
#endif
		ehLogWrite("%s: errore in JPGSave() %d",psImgResize->pszFileDest,iErr);
		return TRUE;
	}

 //printf("ok");
 return FALSE;
}
示例#28
0
void RenderListMarker::paint(PaintInfo& paintInfo, int tx, int ty)
{
    if (paintInfo.phase != PaintPhaseForeground)
        return;
    
    if (style()->visibility() != VISIBLE)
        return;

    IntRect marker = getRelativeMarkerRect();
    marker.move(tx, ty);

    IntRect box(tx + m_x, ty + m_y, m_width, m_height);

    if (box.y() > paintInfo.rect.bottom() || box.y() + box.height() < paintInfo.rect.y())
        return;

    if (hasBoxDecorations()) 
        paintBoxDecorations(paintInfo, box.x(), box.y());

    GraphicsContext* context = paintInfo.context;
    context->setFont(style()->font());

    if (isImage()) {
#if PLATFORM(MAC)
        if (style()->highlight() != nullAtom && !paintInfo.context->paintingDisabled())
            paintCustomHighlight(tx, ty, style()->highlight(), true);
#endif
        context->drawImage(m_image->image(), marker.location());
        if (selectionState() != SelectionNone)
            context->fillRect(selectionRect(), selectionBackgroundColor());
        return;
    }

#if PLATFORM(MAC)
    // FIXME: paint gap between marker and list item proper
    if (style()->highlight() != nullAtom && !paintInfo.context->paintingDisabled())
        paintCustomHighlight(tx, ty, style()->highlight(), true);
#endif

    if (selectionState() != SelectionNone)
        context->fillRect(selectionRect(), selectionBackgroundColor());

    const Color color(style()->color());
    context->setStrokeColor(color);
    context->setStrokeStyle(SolidStroke);
    context->setStrokeThickness(1.0f);
    context->setFillColor(color);

    switch (style()->listStyleType()) {
        case DISC:
            context->drawEllipse(marker);
            return;
        case CIRCLE:
            context->setFillColor(Color::transparent);
            context->drawEllipse(marker);
            return;
        case SQUARE:
            context->drawRect(marker);
            return;
        case LNONE:
            return;
        case ARMENIAN:
        case CJK_IDEOGRAPHIC:
        case DECIMAL_LEADING_ZERO:
        case GEORGIAN:
        case HEBREW:
        case HIRAGANA:
        case HIRAGANA_IROHA:
        case KATAKANA:
        case KATAKANA_IROHA:
        case LDECIMAL:
        case LOWER_ALPHA:
        case LOWER_GREEK:
        case LOWER_LATIN:
        case LOWER_ROMAN:
        case UPPER_ALPHA:
        case UPPER_LATIN:
        case UPPER_ROMAN:
            break;
    }
    if (m_text.isEmpty())
        return;

    TextRun textRun(m_text);

    // Text is not arbitrary. We can judge whether it's RTL from the first character,
    // and we only need to handle the direction RightToLeft for now.
    bool textNeedsReversing = direction(m_text[0]) == RightToLeft;
    Vector<UChar> reversedText;
    if (textNeedsReversing) {
        int length = m_text.length();
        reversedText.resize(length);
        for (int i = 0; i < length; ++i)
            reversedText[length - i - 1] = m_text[i];
        textRun = TextRun(reversedText.data(), length);
    }

    const Font& font = style()->font();
    if (style()->direction() == LTR) {
        int width = font.width(textRun);
        context->drawText(textRun, marker.location());
        const UChar periodSpace[2] = { '.', ' ' };
        context->drawText(TextRun(periodSpace, 2), marker.location() + IntSize(width, 0));
    } else {
        const UChar spacePeriod[2] = { ' ', '.' };
        TextRun spacePeriodRun(spacePeriod, 2);
        int width = font.width(spacePeriodRun);
        context->drawText(spacePeriodRun, marker.location());
        context->drawText(textRun, marker.location() + IntSize(width, 0));
    }
}
示例#29
0
void ImageThread::processRequestResponse(QUrl url, QByteArray ba, bool cached) {
    QString requestURI;
    QList<_IMAGE>   imageList;
    QList<QUrl>     threadList;
    ParsingStatus   status;
    QString         path;
    qint64 bytesWritten;

    QLOG_TRACE() << "ImageThread :: processRequestResponse (" << url.toString() << ", " << QString(ba);

    requestURI = url.toString();
    path = url.path();

    if (isImage(url)) {
        QFile f;
        QRegExp rx(__IMAGEFILE_REGEXP__, Qt::CaseInsensitive, QRegExp::RegExp2);
        QStringList res;
        int pos;

        pos = 0;

        pos = rx.indexIn(requestURI);
        res = rx.capturedTexts();

        if (pos != -1) {
            f.setFileName(getSavepath()+"/"+res.at(1)+res.at(2));

            if (_saveWithOriginalFilename) {
                _IMAGE tmp;

                for (int i=0; i<images.count(); i++) {
                    if (images.at(i).largeURI.endsWith("/"+res.at(1)+res.at(2))) {
                        tmp = images.at(i);

                        f.setFileName(getSavepath()+"/"+tmp.originalFilename);
                        break;
                    }
                }
            }

            f.open(QIODevice::ReadWrite);
            bytesWritten = f.write(ba);
            f.close();

            if (bytesWritten == ba.size()) {
                setCompleted(requestURI, f.fileName());
            }
            else {
                QLOG_ERROR() << "UIImageOverview :: Couldn't save file from URI " << url.toString();
            }
        }

    }
    else {
        iParser->setURL(url);
        status = iParser->parseHTML(ba);

        if (status.hasErrors) {
            QLOG_ERROR() << "ImageOverview :: Parser error " << iParser->getErrorCode();
            switch (iParser->getErrorCode()) {
            case 404:
                stopDownload();
                processCloseRequest();
                break;

            default:
                break;
            }
        }
        else {
            if (status.isFrontpage) {
                QStringList newTab;
                QString v;

                v = getValues();
                newTab = v.split(";;");
                threadList = iParser->getUrlList();

                foreach (QUrl u, threadList) {
                    newTab.replace(0, u.toString());
                    emit createThreadRequest(newTab.join(";;"));
                }

                if (settings->value("options/close_overview_threads", true).toBool()) {
                    emit closeRequest(this, 0);
                }
            }
            else {
                if (status.hasImages) {
示例#30
0
文件: descr.cpp 项目: Oppen/einstein
void TextParser::parseNextPage()
{
    if (tokenizer.isFinished())
        return;
    
    int curPosY = 0;
    int lineWidth = 0;
    TextPage *page = new TextPage();
    std::wstring line;

    while (true) {
        Token t = tokenizer.getNextToken();
        if (Token::Eof == t.getType())
            break;
        if (Token::Para == t.getType()) {
            if (0 < line.length())
                addLine(page, line, curPosY, lineWidth);
            if (! page->isEmpty())
                curPosY += 10;
        } else if (Token::Word == t.getType()) {
            const std::wstring &word = t.getContent();
            if (isImage(word)) {
                addLine(page, line, curPosY, lineWidth);
                SDL_Surface *image = getImage(keywordToImage(word));
                if ((image->h + curPosY < pageHeight) || page->isEmpty()) {
                    int x = offsetX + (pageWidth - image->w) / 2;
                    page->add(new Picture(x, offsetY + curPosY, image));
                    curPosY += image->h;
                } else {
                    tokenizer.unget(t);
                    break;
                }
            } else {
                int width = font.getWidth(word);
                if (lineWidth + width > pageWidth) {
                    if (! lineWidth) {
                        line = word;
                        addLine(page, line, curPosY, lineWidth);
                    } else {
                        addLine(page, line, curPosY, lineWidth);
                        if (curPosY >= pageHeight) {
                            tokenizer.unget(t);
                            break;
                        }
                        line = word;
                        lineWidth = width;
                    }
                } else {
                    lineWidth += width;
                    if (line.size()) {
                        line += L' ';
                        lineWidth += spaceWidth;
                    }
                    line += word;
                }
            }
        }
        if (curPosY >= pageHeight)
            break;
    }
    addLine(page, line, curPosY, lineWidth);
    if (! page->isEmpty())
        pages.push_back(page);
    else
        delete page;
}