Example #1
0
static void setFormatOption(QFormat& fmt, const QString& field, const QString& value){
	if ( field == "priority" )
		fmt.setPriority(value.toInt());
	else if ( field == "bold" )
		fmt.weight = bool_cast(value) ? QFont::Bold : QFont::Normal;
	else if ( field == "italic" )
		fmt.italic = bool_cast(value);
	else if ( field == "overline" )
		fmt.overline = bool_cast(value);
	else if ( field == "underline" )
		fmt.underline = bool_cast(value);
	else if ( field == "strikeout" )
		fmt.strikeout = bool_cast(value);
	else if ( field == "waveUnderline" )
		fmt.waveUnderline = bool_cast(value);
	else if ( field == "color" || field == "foreground" )
		fmt.foreground = QColor(value);
	else if ( field == "background" )
		fmt.background = QColor(value);
	else if ( field == "linescolor" )
		fmt.linescolor = QColor(value);
	else if ( field == "fontFamily" )
		fmt.fontFamily = value;
	else if ( field == "pointSize" )
		fmt.pointSize = value.toInt();
    else if ( field == "wrapAround" )
        fmt.wrapAround = bool_cast(value);
}
/*!
	\overload
	\param elem Source element to scan
	\param ignoreNewIds whether unknown format identifiers should be ignored
	
	The given dom element must contain a proper version attribute and format
	data as child elements (<format> tags)
	
	\note Previous content is not discarded
*/
void QFormatScheme::load(const QDomElement& elem, bool ignoreNewIds)
{
	if ( elem.attribute("version") < QFORMAT_VERSION )
	{
		qWarning("Format encoding version mismatch : [found]%s != [expected]%s",
				qPrintable(elem.attribute("version")),
				QFORMAT_VERSION);
		
		return;
	}
	
	QDomElement e, c;
	QDomNodeList l, f = elem.elementsByTagName("format");
	
	for ( int i = 0; i < f.count(); i++ )
	{
		e = f.at(i).toElement();
		
		if ( ignoreNewIds && !m_formatKeys.contains(e.attribute("id")) )
			continue;
		
		l = e.childNodes();
		
		QFormat fmt;
		
		for ( int i = 0; i < l.count(); i++ )
		{
			c = l.at(i).toElement();
			
			if ( c.isNull() )
				continue;
			
			QString field = c.tagName(),
					value = c.firstChild().toText().data();
			
			if ( field == "bold" )
				fmt.weight = bool_cast(value) ? QFont::Bold : QFont::Normal;
			else if ( field == "italic" )
				fmt.italic = bool_cast(value);
			else if ( field == "overline" )
				fmt.overline = bool_cast(value);
			else if ( field == "underline" )
				fmt.underline = bool_cast(value);
			else if ( field == "strikeout" )
				fmt.strikeout = bool_cast(value);
			else if ( field == "waveUnderline" )
				fmt.waveUnderline = bool_cast(value);
			else if ( field == "color" || field == "foreground" )
				fmt.foreground = QColor(value);
			else if ( field == "background" )
				fmt.background = QColor(value);
			else if ( field == "linescolor" )
				fmt.linescolor = QColor(value);
			
		}
		
		setFormat(e.attribute("id"), fmt);
	}
}
/*!
	\overload
	\brief Load format data from a QSettings object
	\param s QSettings object from which data will be fetched
	\param ignoreNewIds whether unknown format identifiers should be ignored
	
	The QSettings object is assumed to be initialized properly and to
	point to a correct location.
	
	\note Previous content is not discarded
*/
void QFormatScheme::load(QSettings& s, bool ignoreNewIds)
{
	QString version = s.value("version").toString();
	
	if ( version < QFORMAT_VERSION )
	{
		qWarning("Format encoding version mismatch : [found]%s != [expected]%s",
				qPrintable(version),
				QFORMAT_VERSION);
		
		return;
	}
	
	s.beginGroup("data");
	
	QStringList l = s.childGroups();
	
	foreach ( QString id, l )
	{
		if ( ignoreNewIds && !m_formatKeys.contains(id) )
			continue;
		
		s.beginGroup(id);
		
		QFormat fmt;
		QStringList fields = s.childKeys();
		
		foreach ( QString field, fields )
		{
			QString value = s.value(field).toString();
			
			if ( field == "bold" )
				fmt.weight = bool_cast(value) ? QFont::Bold : QFont::Normal;
			else if ( field == "italic" )
				fmt.italic = bool_cast(value);
			else if ( field == "overline" )
				fmt.overline = bool_cast(value);
			else if ( field == "underline" )
				fmt.underline = bool_cast(value);
			else if ( field == "strikeout" )
				fmt.strikeout = bool_cast(value);
			else if ( field == "waveUnderline" )
				fmt.waveUnderline = bool_cast(value);
			else if ( field == "color" || field == "foreground" )
				fmt.foreground = QColor(value);
			else if ( field == "background" )
				fmt.background = QColor(value);
			else if ( field == "linescolor" )
				fmt.linescolor = QColor(value);
			
		}
		
		setFormat(id, fmt);
		s.endGroup();
	}
Example #4
0
static bool
DkimWildcard_matchPubkeyGranularityImpl(const char *pattern_head, const char *pattern_tail,
                                        const char *target_head, const char *target_tail,
                                        bool accept_wildcard)
{
    /*
     * the ABNF of key-g-tag-lpart says only one wildcard is acceptable.
     * But '*' itself is included in dot-atom-text.
     * So this function treats the first occurrence of '*' as wildcard,
     * and next or later occurrence of '*' as character.
     *
     * [RFC4871] 3.6.1.
     * key-g-tag       = %x67 [FWS] "=" [FWS] key-g-tag-lpart
     * key-g-tag-lpart = [dot-atom-text] ["*" [dot-atom-text] ]
     */

    const char *pattern;
    const char *target;

    for (pattern = pattern_head, target = target_head; pattern < pattern_tail; ++pattern, ++target) {
        if ('*' == *pattern) {
            if (accept_wildcard) {
                // treat '*' as wildcard
                ++pattern;
                for (const char *bq = target_tail; target <= bq; --bq) {
                    if (DkimWildcard_matchPubkeyGranularityImpl
                        (pattern, pattern_tail, bq, target_tail, false)) {
                        return true;
                    }   // end if
                }   // end for
                return false;
            } else {
                // treat '*' as (not wildcard but) character
                if (target_tail <= target || '*' != *target) {
                    return false;
                }   // end if
            }   // end if
        } else if (IS_ATEXT(*pattern) || '.' == *pattern) {
            /*
             * compare case-sensitively.
             *
             * [RFC6376] 3.2.
             * Values MUST be
             * processed as case sensitive unless the specific tag description of
             * semantics specifies case insensitivity.
             *
             * And the local-part of mailbox is essentially treated as case-sensitive.
             *
             * [RFC5321] 2.4.
             * ... The
             * local-part of a mailbox MUST BE treated as case sensitive.
             */
            if (target_tail <= target || *pattern != *target) {
                return false;
            }   // end if
        } else {
            // neither atext nor '.' (included in dot-atom-text)
            return false;
        }   // end if
    }   // end for
    return bool_cast(pattern == pattern_tail && target == target_tail);
}   // end function: DkimWildcard_matchPubkeyGranularityImpl
Example #5
0
void Directx::TShaderState::BindTexture(size_t TextureIndex,const TTexture& Texture)
{
	//	allocate sampler
	{
		std::shared_ptr<AutoReleasePtr<ID3D11SamplerState>> pSampler( new AutoReleasePtr<ID3D11SamplerState> );
		auto& Sampler = pSampler->mObject;
		auto& TextureParams = Texture.mSamplingParams;

		D3D11_SAMPLER_DESC samplerDesc;
		samplerDesc.Filter = TextureParams.mLinearFilter ? D3D11_FILTER_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_POINT;
		samplerDesc.AddressU = TextureParams.mWrapU ? D3D11_TEXTURE_ADDRESS_WRAP : D3D11_TEXTURE_ADDRESS_CLAMP;
		samplerDesc.AddressV = TextureParams.mWrapV ? D3D11_TEXTURE_ADDRESS_WRAP : D3D11_TEXTURE_ADDRESS_CLAMP;
		samplerDesc.AddressW = TextureParams.mWrapW ? D3D11_TEXTURE_ADDRESS_WRAP : D3D11_TEXTURE_ADDRESS_CLAMP;
		samplerDesc.MipLODBias = 0.0f;
		samplerDesc.MaxAnisotropy = 1;
		samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
		samplerDesc.BorderColor[0] = 0;
		samplerDesc.BorderColor[1] = 0;
		samplerDesc.BorderColor[2] = 0;
		samplerDesc.BorderColor[3] = 0;
		samplerDesc.MinLOD = TextureParams.mMinLod;
		samplerDesc.MaxLOD = TextureParams.mMaxLod == -1 ? D3D11_FLOAT32_MAX : TextureParams.mMaxLod;

		// Create the texture sampler state.
		auto& Device = GetDevice();
		auto Result = Device.CreateSamplerState( &samplerDesc, &Sampler );
		Directx::IsOkay( Result, "Creating sampler" );
		mSamplers.PushBack( pSampler );
	}

	//	create resource view (resource->shader binding)
	{
		std::shared_ptr<AutoReleasePtr<ID3D11ShaderResourceView>> pResourceView( new AutoReleasePtr<ID3D11ShaderResourceView> );
		auto& ResourceView = *pResourceView;

		ID3D11Resource* Resource = Texture.mTexture.mObject;

		//	below will fail if bind flags doesn't have D3D11_BIND_SHADER_RESOURCE
		auto Mode = Texture.GetMode();

		//	no description means it uses original params
		const D3D11_SHADER_RESOURCE_VIEW_DESC* ResourceDesc = nullptr;
		D3D11_SHADER_RESOURCE_VIEW_DESC TempResourceDesc;

		//	if internal type is typeless, and there is no raw-view setting, we need to set the format
		if ( Directx::FormatIsTypeless(Texture.GetDirectxFormat()) )
		{
			D3D11_TEXTURE2D_DESC SrcDesc;
			Texture.mTexture.mObject->GetDesc( &SrcDesc );
			bool AllowsRawView = bool_cast(SrcDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS);
			if ( !AllowsRawView )
			{
				UINT MostDetailedMip;
				UINT MipLevels;
				TempResourceDesc.Texture2D.MipLevels = SrcDesc.MipLevels;
				TempResourceDesc.Texture2D.MostDetailedMip = 0;
				//	gr: what goes here?
				TempResourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
				TempResourceDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
				ResourceDesc = &TempResourceDesc;
			}
		}

		auto& Device = GetDevice();
		auto Result = Device.CreateShaderResourceView( Resource, ResourceDesc, &ResourceView.mObject );
		Directx::IsOkay( Result, "Createing resource view");
		mResources.PushBack( pResourceView );
	}
}